Problem · Medium · 20 min
Revenue for each month
- Medium
- Dates
- Grouping and totals
A shop keeps its payments in the table payments.
| Column | Meaning |
|---|---|
id |
The number of the payment. It is unique. |
paid_on |
The day of the payment, as text in the form 2024-01-31. |
amount |
The amount of the payment, as a whole number. |
status |
paid, refunded or failed. |
Write one query that returns one row for each month that has at least one payment with the status paid. Only payments with the status paid count. The columns are:
month: the month, as text in the form2024-01.payments: the number of paid payments in that month.revenue: the sum of theamountof those payments.
Sort the rows by month, the oldest first. A month with no paid payments is not in the result.
Tasks
2 to do
Task 1, not checked yet. Return the right rows for the example data.
Task 2, not checked yet. Return the right rows for other data that you cannot see.
Task 1 of 2
Return the right rows for the example data.