SQL常用语法总结(MySql)持续更新

MySql常用Sql语法总结——持续更新

强制使用索引

FORCE INDEX (索引名称)

示例:

select * from tableName  FORCE INDEX ( nameIndex ) where id  > 10

按时间粒度查询
Mysql按周,按月,按日,按小时分组统计数据

按周

select DATE_FORMAT(create_time,'%Y%u') weeks,count(caseid) count from tc_case group by weeks;

按月

select DATE_FORMAT(create_time,'%Y%m') months,count(caseid) count from tc_case group by months; 

按天

select DATE_FORMAT(create_time,'%Y%m%d') days,count(caseid) count from tc_case group by days;  

按小时

select DATE_FORMAT(create_time,'%Y%m%d%H') hours,count(caseid) count from tc_case group by hours;

具体请参考

你可能感兴趣的:(SQL,mysql,MySQL,sql,数据库)