概述
查询相关
count对列值为null不统计的问题
对于统计记录总数时,有时会遇到某个字段值为空不统计的问题,可以通过IFNULL函数解决。
select count(distinct id,name,IFNULL(col3,‘0’)) from t_xxx_table;
示例:
SELECT count(DISTINCT t.id, IFNULL(f.oid,-2))
FROM t_p_t1 t left join t_p_t2 f ON t.id = f.pid AND f.is_delete = 0
索引相关
DROP INDEX idx_appKey_cTime ON t_p_p1;
CREATE INDEX idx_appKey_cTime ON t_p_p1 ( app_key
, cid
, delete
, create_time
) USING BTREE;
表相关
通过select语句创建表
CREATE TABLE IF NOT EXISTS temp_config AS (SELECT * FROM t_p_config where config is not NULL);
也可以给表添加索引,同时指定存储引擎
CREATE TABLE IF NOT EXISTS temp_config1 (INDEX(config)) ENGINE=InnoDB AS (SELECT * FROM t_p_config where config is not NULL);