日期处理相关:
查询datetime属于某一天的记录:使用date()方法使datetime扔掉时间的部分,只留下日期
select * from order where date(create_time) = '2017-07-20';
查询昨天的记录:
where to_days(now())-to_days(create_time) = 1;
count / sum嵌套查询:case when ...then ...end
查询订单表总数和状态为1的总数
select count(order_id) as new ,count(case when status=1 then order_id end ) as success from kn_order
性能相关
1、在用户表查出所有的版本号,要去重,有两种办法:distinct和group by
select version from user GROUP BY version;
select distinct version from user ;
通过建索引能有效提高速度,group by的速度始终比distinct快
ALTER TABLE `user` ADD INDEX `version_index` (`version`) ;