在过去7天内获得订单

时间:2014-04-01 17:50:26

标签: mysql

我试图在我的网站上过去7天获取订单并创建此查询

SELECT
DATE(O.CreatedAt),
SUM(CASE WHEN O.CompletedAt IS NULL THEN 1 ELSE 0 END) AS New,
SUM(CASE WHEN O.CompletedAt IS NOT NULL THEN 1 ELSE 0 END) AS Done
FROM Orders O
WHERE DATEDIFF(O.CreatedAt, CURDATE()) > -7
GROUP BY DATE(O.CreatedAt)

运行此查询我得到以下结果:

 2014-03-27 94  0
 2014-03-28 1   0
 2014-04-01 2   0

但是,如果没有订单,我需要显示价值,例如:

 2014-03-26 94  0
 2014-03-27 94  0
 2014-03-28 1   0
 2014-03-29 0   0
 2014-03-30 0   0
 2014-03-31 0   0
 2014-04-01 2   0

任何人都可以帮助我吗?

此致

0 个答案:

没有答案