mysql中查询1:本月2:本周 3:本季度
SELECT
date_format(( now() + INTERVAL -( 11 ) MONTH ), '%Y年%m月' ) AS `months` UNION
SELECT
date_format(( now() + INTERVAL -( 10 ) MONTH ), '%Y年%m月' ) AS `months` UNION
SELECT
date_format(( now() + INTERVAL -( 9 ) MONTH ), '%Y年%m月' ) AS `months` UNION
SELECT
date_format(( now() + INTERVAL -( 8 ) MONTH ), '%Y年%m月' ) AS `months` UNION
SELECT
date_format(( now() + INTERVAL -( 7 ) MONTH ), '%Y年%m月' ) AS `months` UNION
SELECT
date_format(( now() + INTERVAL -( 6 ) MONTH ), '%Y年%m月' ) AS `months` UNION
SELECT
date_format(( now() + INTERVAL -( 5 ) MONTH ), '%Y年%m月' ) AS `months` UNION
SELECT
date_format(( now() + INTERVAL -( 4 ) MONTH ), '%Y年%m月' ) AS `months` UNION
SELECT
date_format(( now() + INTERVAL -( 3 ) MONTH ), '%Y年%m月' ) AS `months` UNION
SELECT
date_format(( now() + INTERVAL -( 2 ) MONTH ), '%Y年%m月' ) AS `months` UNION
SELECT
date_format(( now() + INTERVAL -( 1 ) MONTH ), '%Y年%m月' ) AS `months` UNION
SELECT
date_format( now(), '%Y年%m月' ) AS `months`
Mysql计算月份差
查询当前时间之前2个小时的日期:SELECT NOW()-INTERVAL '2' HOUR;查询两天前的时间:SELECT NOW(),SUBDATE(NOW(),INTERVAL 2 DAY);
比如查询当前时间前一年又三个月的时间,可以这样:SELECT NOW(),NOW()-INTERVAL '1 3' YEAR_MONTH;
SELECT *,PERIOD_DIFF(DATE_FORMAT(now(),'%Y%m'), DATE_FORMAT(t_scores.t,'%Y%m'))
from t_scores
列表数据