要求:在t_cms_table表里查出每个createId 出现的次数,并按照从大到小的顺序排列
例子:根据createId 分组,之后再排序。
SELECT createId ,COUNT(createId) as obj FROM `t_cms_table` GROUP BY createId ORDER BY obj desc
列分割做条件
SELECT * FROM 表名 where xn='2017-2018' and xq='1' and xqj = '四' and to_number(substr(zc,0,1)) <7 and to_number(substr(zc,3,4)) >7
时间函数
取当前时间的前后两天(格式为YYYY-MM-DD’):
select adddate(curdate(), '-2 days');
select adddate(curdate(), '+2 days');
select curdate() + INTERVAL -2 DAY ;
select curdate() + INTERVAL 2 DAY ;
取当前时间的前五分钟:
select now() - interval 5 minute;
取当前时间的前一个月:
select now() - interval 5 month;