SQL Quest › SQL Interview Questions › Subqueries & CTEs
Failure Rate by Torque Bucket
Bucket units by torque into 'Low' (< 30), 'Medium' (30-50), 'High' (>= 50) Nm. Compute failure rate per bucket per quality grade. Show type, torque_bucket, unit_count, failures, failure_rate_pct. Order by type, torque_bucket.
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 |
failure_events
| udi | machine_failure | twf | hdf | pwf | osf | rnf |
|---|---|---|---|---|---|---|
| 5640 | 0 | 0 | 0 | 0 | 0 | 1 |
| 2171 | 0 | 0 | 0 | 0 | 0 | 0 |
| 228 | 0 | 0 | 0 | 0 | 0 | 0 |
Expected output: Where do failures cluster?
Hint
Concepts
SELECT CTE JOIN CASE GROUP BY Multi-CTE
Practise the topic: SQL practice questions · CTE practice · JOIN practice · CASE WHEN practice · GROUP BY exercises · 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