SUM销售价格按星期几

时间:2017-08-16 06:48:14

标签: mysql

我已经为我的解决方案找到了完美的代码,但遗憾的是我还没有找到一种方法可以在那一天添加SUM selling_price一小段内容。< / p>

SQL代码:

SELECT
  COUNT(WEEKDAY(`date`) = 0 OR NULL) AS Mon,
  COUNT(WEEKDAY(`date`) = 1 OR NULL) AS Tue,
  COUNT(WEEKDAY(`date`) = 2 OR NULL) AS Wed,
  COUNT(WEEKDAY(`date`) = 3 OR NULL) AS Thu,
  COUNT(WEEKDAY(`date`) = 4 OR NULL) AS Fri,
  COUNT(WEEKDAY(`date`) = 5 OR NULL) AS Sat,
  COUNT(WEEKDAY(`date`) = 6 OR NULL) AS Sun
FROM orders
WHERE `date` >= CURRENT_DATE() - INTERVAL ( WEEKDAY(CURRENT_DATE()) ) DAY
  AND `date` <  CURRENT_DATE() + INTERVAL 1 DAY

1 个答案:

答案 0 :(得分:0)

SUM(IF(WEEKDAY(`date`) = 0,selling_price,0)) AS Mon_Price