mysql查询最近4天的数据,没有数据自动补0

xiaoxiao2021-02-28  32

SELECT   click_date,   count(plan_order_id) num 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   ) a   LEFT JOIN t_plan_order tpo on tpo.plan_order_date = a.click_date and tpo.is_delete = 0 GROUP BY   a.click_date

结果如下

转载请注明原文地址: https://www.6miu.com/read-2300039.html

最新回复(0)