1 查询前7天的日期
select a.click_date
from (
SELECT date_sub(curdate(), interval 1 day) as click_date
union all
SELECT date_sub(curdate(), interval 2 day) as click_date
union all
SELECT date_sub(curdate(), interval 3 day) as click_date
union all
SELECT date_sub(curdate(), interval 4 day) as click_date
union all
SELECT date_sub(curdate(), interval 5 day) as click_date
union all
SELECT date_sub(curdate(), interval 6 day) as click_date
union all
SELECT date_sub(curdate(), interval 7 day) as click_date
) a
查询结果
2 查询订单表出现日期,成交额总和
没有出现的日期,不会被查出来
select DATE_FORMAT(o_id,"%Y-%m-%d") as date,sum(o_turnover)*0.15 u_commission from orders
where o_id between "2021-05-26" and "2021-06-02" and uid = 2
group by date;
3 根据日期统计数据
select DATE_FORMAT(date,"%Y-%m-%d") day,count(*) num from log group by day;