MySQL 笔记 5

视图

  • 视图是虚拟的表

视图的作用

    MySQL 笔记 4

    插入数据

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    INSERT INTO customers VALUES(NULL, 'Fang');

    -- 推荐更安全、扩展性更好的方式
    INSERT INTO customers(cust_id, cust_name) VALUES(NULL, 'Fang');

    -- 进一步,无需插入 AUTO_INCREMENT 属性的列
    INSERT INTO customers(cust_name) VALUES('Fang');

    -- 插入多条数据,单条语句插入比多次语句性能更高
    INSERT INTO customers(cust_name) VALUES('Fang'), ('Quan');

    -- 插入检索出的数据
    INSERT INTO customers(cust_id, cust_name) SELECT cust_id, cust_name FROM custnew;

    MySQL 笔记 3

    分组数据

    1
    2
    3
    SELECT vend_id COUNT(*) AS num_prods FROM products GROUP BY vend_id;

    SELECT cust_id, COUNT(*) AS orders FROM orders GROUP BY cust_id HAVING COUNT(*) >= 2;

    MySQL 笔记 2

    创建计算字段

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    -- 拼接字段 Concat()
    SELECT Concat(vend_name, ' (', vend_country, ')') FROM vendors ORDER BY vend_name;

    -- Trim() 去除空格
    SELECT Concat(RTrim(vend_name), ' (', RTrim(vend_country), ')') FROM vendors ORDER BY vend_name;

    -- 使用别名 AS
    SELECT Concat(RTrim(vend_name), ' (', RTrim(vend_country), ')') AS vend_title FROM vendors ORDER BY vend_name;

    -- 执行算术计算
    SELECT prod_i, quantity, item_price, quantity*item_price AS expanded_price FROM orderitems WHERE order_num = 20005;

    MySQL 笔记 1

    常用操作

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    -- 显示数据库
    SHOW DATABASES;

    -- 选择数据库
    USE some_db;

    -- 显示表
    SHOW TABLES;

    -- 显示表的列信息
    SHOW COLUMNS FROM some_table;
    DESCRIBE some_table;

    -- 显示数据库服务器状态信息
    SHOW STATUS;

    -- 显示授予用户的权限
    SHOW GRANTS;

    -- 显示服务器错误信息/警告信息
    SHOW ERRORS;
    SHOW WARNINGS;

    Shell 结束某进程的子孙进程

    不知Linux原生是否有自带这类命令……

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    kill_pid_recursively()
    {
    local pid=$1
    local parent_pid=$2
    if [ ! -z ${pid} ]; then
    for child_pid in `pgrep -P ${pid}`; do
    kill_pid_recursively ${child_pid} ${pid}
    done
    echo "kill PID: ${pid}, its PPID is ${parent_pid}"
    kill -9 ${pid}
    fi
    }

    kill_pid_recursively ${SOME_PID} 'nothing'

    Bootstrap-AlertDialog

    依赖

    • Bootstrap3
    • jquery-tmpl

    模板代码

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    <script id="template-dialog-alert" type="text/x-jquery-tmpl">
    <div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-sm">
    <div class="modal-content">
    <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
    <h5 class="modal-title">提示</h5>
    </div>
    <div class="modal-body">
    </div>
    </div>
    </div>
    </div>
    </script>

    JavaScript 设计模式

    《JavaScript 面向对象编程指南》笔记

    单例模式

    1
    2
    3
    4
    5
    6
    function Logger() {
    if (!Logger.single_instance) {
    Logger.single_instance = this;
    }
    return Logger.single_instance;
    }

    JavaScript 编程模式

    《JavaScript 面向对象编程指南》笔记

    1. 行为隔离

    内容(HTML),外观(CSS),行为(JavaScript)

    1.1 内容

    • 避免在HTML标签中使用 style 属性
    • 不要使用与外观有关的 HTML 标签,例如<font>
    • 尽量根据语义需要来选择标签

    OS X 环境下 php-redis 的安装

    使用 Homebrew,先安装 homebrew-php,再安装 phpredis