🎯 Few days left this month Support SQLTest.online and help us keep SQL practice free for everyone. Donate today →
SQL code copied to buffer
Task 10:

Analyze customer payments

MySQL
For each customer, in the payment table, find the dates of his first and last payment, as well as the amount of all payments.
The query should return four columns: customer_id, first_payment_date – date of the first payment (in the format “YYYY-MM-DD”), last_payment_date – date of the last payment (in the format “YYYY-MM-DD”) and total_paid – total amount of client payments sorted in descending order of amount payments (in case of equal payment amounts - by ascending customer_id).
Expected result Columns: 4 · Rows: 599
customer_id first_payment_date last_payment_date total_paid

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
The query result will appear here. Ctrl+Enter - Run query