Monthly Order Status Pivot
Medium
Subtotals & Pivoting
Return one row per month with the number of 'paid' orders and the number of 'refunded' orders as separate columns, ordered by month.
Table schema
Orders(id INT PRIMARY KEY, order_date DATE, status VARCHAR(10))Sample data
id | order_date | status
1 | 2026-01-03 | paid
2 | 2026-01-10 | refunded
3 | 2026-01-20 | paid
4 | 2026-02-02 | paid
5 | 2026-02-15 | paid
6 | 2026-02-20 | refunded
Discussion
No discussions yet.
Shalyam Support
Hi! Ask us anything — we'll reply on WhatsApp or Telegram within 24 hours.