SQL QuestSQL Interview Questions › Window Functions

Top 5 Torque Per Quality

HardProQuerying BasicsWindow Functions

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

udiproduct_idtypetool_wear_min
5640L52819L180
2171M17030M10
228L47407L168

operational_data

udiair_temp_kprocess_temp_krotational_speed_rpmtorque_nm
5640302.6312.1166828.7
2171299.4309.1150043.3
228298.3308.5153936.1

Expected output: 5 highest-torque units per L/M/H

Hint

This is a Pro challenge — the hint, the step-by-step tutor and the reference solution open in the app.

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

Cumulative Distinct Customers Over TimeHard · FreeSalary Rank Within DepartmentHard · FreeRunning Total RevenueHard · FreeYear-over-Year GrowthHard · Free7-Day Rolling Revenue AverageHard · FreeMulti-CTE Revenue PipelineHard · Free

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