统计近30天的数据,没有则补0
SELECT
t.dates,
count( d.id )
FROM
(
SELECT
@s := @s + 1 AS indexs,
DATE_FORMAT( DATE( DATE_SUB( CURRENT_DATE, INTERVAL @s DAY ) ), '%Y-%m-%d' ) AS dates
FROM
mysql.help_topic,
( SELECT @s := - 1 ) temp #不想包含当天,@s:=0
WHERE
@s < 30
ORDER BY
dates
) t
LEFT JOIN dt_memoir d ON t.dates = date( d.create_time ) and d.dept_id = '10958'
GROUP BY
t.dates
查询最近4个季度的数据
SELECT CONCAT(YEAR(DATE_SUB(NOW(), INTERVAL 4 QUARTER)), '-Q', QUARTER(DATE_SUB(NOW(), INTERVAL 4 QUARTER))) AS quarter;
记录一下