如题
这个分两种情况:
-
不需要补0
-- 查询最近七天工单
select date_format(createTime,"%Y-%m-%d") as days,count(*) as count
from rd_order where DATE_SUB(CURDATE(),INTERVAL 6 DAY) <= createTime GROUP BY days
-- 查询最近六月工单
select date_format(createTime,"%Y-%m") as months,count(*) as count
from rd_order where DATE_SUB(CURDATE(),INTERVAL 5 MONTH) <= createTime GROUP BY months
-- 查询最近六周订单
select YEARWEEK(date_format(createTime,"%Y-%m-%d")) as weeks,count(*) as count
from rd_order where DATE_SUB(CURDATE(),INTERVAL 5 WEEK) <= createTime GROUP BY weeks
-
需要补0
SELECT b.click_date,IFNULL(a.count,0) as count from
-- 查询最近七天工单
(select date_format(createTime,"%Y-%m-%d") as days,count(*) as count
from rd_order where DATE_SUB(CURDATE(),INTERVAL 6 DAY) <= createTime