SQL Quest › SQL Interview Questions › Window Functions
Top 5 Torque Per Quality
For each quality grade, find the 5 units operating at highest torque. Use RANK() OVER (PARTITION BY type ORDER BY torque_nm DESC). Show type, udi, torque_nm, rank_in_type. Filter to rank <= 5. Order by type, rank_in_type.
Solve it in the browser editor →
Runs on SQLite in your browser, graded against the expected result, no signup. A wrong answer gets a diagnosis, not just "incorrect".
Schema
products
| udi | product_id | type | tool_wear_min |
|---|---|---|---|
| 5640 | L52819 | L | 180 |
| 2171 | M17030 | M | 10 |
| 228 | L47407 | L | 168 |
operational_data
| udi | air_temp_k | process_temp_k | rotational_speed_rpm | torque_nm |
|---|---|---|---|---|
| 5640 | 302.6 | 312.1 | 1668 | 28.7 |
| 2171 | 299.4 | 309.1 | 1500 | 43.3 |
| 228 | 298.3 | 308.5 | 1539 | 36.1 |
Expected output: 5 highest-torque units per L/M/H
Hint
Concepts
SELECT Window Functions RANK PARTITION BY
Practise the topic: SQL practice questions · Window function practice · Ranking function practice · Advanced SQL interview questions
Related questions
Where would this cost you points in an interview?
Ten questions, no signup: a Skillmap across nine SQL skills and the one to fix first.
Take the readiness test