Practice

Problem 4 of 8

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 form 2024-01.
  • payments: the number of paid payments in that month.
  • revenue: the sum of the amount of 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

  1. Task 1, not checked yet. Return the right rows for the example data.

  2. 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.

All tasks

query.sql

Ctrl+Enter runs your code. Ctrl+Shift+Enter runs all the tests. Press Esc, then Tab, to leave the editor.

Output

Press Run to see your result

Your output shows here. Press Run to try your code.