I have a transaction table and I want to sum the total of daily sales and display it on a graph related to the past 7 days.
SELECT weekday(date), sum(amount) FROM m1pay_dashboard.transactions where date > (DATE(NOW()) - INTERVAL 7 DAY)
group by weekday(date)
This query will display the output below:
| | weekday | sale |
| - | ---------- | ----- |
| 1 | Monday | 20 |
| 2 | Tuesday | 50 |
| 3 | Friday | 120 |
| 4 | Saturday | 140 |
| 5 | Sunday | 110 |
but I need to have the sale regarding all 7 days. (displaying zero for days which does not exist) here is the sample output which I need:
| | weekday | sale |
| - | ---------- | ----- |
| 1 | Monday | 20 |
| 2 | Tuesday | 50 |
| 3 | Wednesday | 0 |
| 4 | Thursday | 0 |
| 5 | Friday | 120 |
| 6 | Saturday | 140 |
| 7 | Sunday | 110 |