SQL Round, Kestrel's Customers
A second interview-style SQL round on Kestrel's live database: five questions about customers, graded by the rows they return.
- Intermediate
- 20 min
- Challenge
- SQL
- PostgreSQL
- Kestrel
- Interview
Overview
Harpreet is planning a loyalty scheme and Neha wants the monthly numbers. The answers are in the kestrel database (customers, orders, stores). Expect HAVING, windows over months and dates measured against the data, not against today.
Write each answer as one SELECT in its own file, ~/rounds/q1.sql, ~/rounds/q2.sql and so on. Try it with psql kestrel -f ~/rounds/q1.sql. It is graded by the rows it returns: exactly the columns asked for, in that order, sorted as asked. Column names do not matter. Money is integer paise, as everywhere at Kestrel: never divide it.
What done looks like
- Filter groups with HAVING
- Rank by a sum and break ties
- Compare each month with the one before (LAG)
- Count with a condition inside an aggregate
- Measure dates against the data itself
Before you start
- Databases & SQL, or SELECT, JOIN, GROUP BY and ORDER BY
- Timed challenge: failed checks return no hints