Senior
SQL task: list clients whose average payment amount is greater than 2000
sobes.tech AI
Answer from AI
To solve the task, you need to group payments by clients, calculate the average payment amount for each client, and filter those with an average greater than 2000.
Example SQL query:
SELECT client_id
FROM payments
GROUP BY client_id
HAVING AVG(amount) > 2000;
Here:
paymentsis the table with payments, which has fieldsclient_idandamount.GROUP BY client_idgroups records by clients.HAVING AVG(amount) > 2000filters groups where the average payment amount is greater than 2000.
If you need to display not only the ID but also other client data, you can perform a JOIN with the clients table.