Average Trade Amount by Segment and Month
Problem
**[Asked at Goldman Sachs]**
For each combination of **client segment** and **month**, compute the
**average trade amount** (rounded to 2 dp).
Return `segment`, `month` (YYYY-MM), and `avg_amount`, ordered by month then segment.
Tables
Example rows — the live problem includes the full dataset.
clients
| client_id | name | segment |
|---|
trades
| trade_id | client_id | amount | trade_date |
|---|
Expected output
Your answer should return 5 rows with the columns segment, month, avg_amount.
Starter code (SQL)
SELECT *
FROM clients;Solve this SQL question free
Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock