Lewis Larf Lewis Larf -3 years ago 68
MySQL Question

SUM selling price by day of the week

I've found perfect code for my solution, but sadly I haven't found a way to add there one small addition which would

SUM
selling_price
for that exact day.

SQL Code:

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

Answer Source
SUM(IF(WEEKDAY(`date`) = 0,selling_price,0)) AS Mon_Price
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download