SQL Round, Kestrel's Shelves
A third interview-style SQL round on Kestrel's live database: five questions about stock and what sells, graded by the rows they return.
- Intermediate
- 20 min
- Challenge
- SQL
- PostgreSQL
- Kestrel
- Interview
Overview
Rohit's riders keep arriving at empty shelves. The answers are in the kestrel database (stores, products, stock, orders, order_items). Expect joins across four tables, shares of a total and one row per group.
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
- Join stock to the stores and products it names
- Filter groups with HAVING
- Compute a share of a total with a window over the whole result
- Pick the second row of each group
- Find the best source for each missing item
Before you start
- Databases & SQL, or SELECT, JOIN, GROUP BY and ORDER BY
- Timed challenge: failed checks return no hints