🙏 We need your help! SQLtest.online has no ads and lives only on donations. Even a small amount helps. Donate now →
SQL code copied to buffer
Task 132:

Monthly Payments with Empty Months

MySQL
The payment table has payments from May 2005 to February 2006, but not every month has them. Build a monthly report for every month from May 2005 to February 2006 inclusive, including the months without payments.
Output columns: year, month (numbers), payments (the number of payments, 0 for a month without payments) and total (the sum of amount, 0 for a month without payments). Sort by year and month.
Expected result Columns: 4 · Rows: 10
year month payments total

Sample rows open after wrong checks: 0 of 2

Write your query below and click "Check it!". Tables are described in the right pane.

Tutorial

By checking a query, you agree that it is stored without your account details and may be included in anonymized datasets, including for AI training. Learn more

The query result will appear here. Ctrl+Enter - Run query