Top Performing Models
An easy SQL interview practice problem on DataDriven. Write the query and run it against a real database, with instant feedback.
- Domain
- SQL
- Difficulty
- easy
- Seniority
- L3
Problem
Which models in our ml_models registry have an accuracy of 0.90 or above? Return every field for each one, highest accuracy first.
The models that actually perform.
Tables
ml_models
Columns: model_id INTEGER, mdl_name TEXT, version TEXT, accuracy REAL, status TEXT, train_at TEXT, framework TEXT
| model_id | mdl_name | version | accuracy | status | train_at | framework |
|---|---|---|---|---|---|---|
| 123 | rec_engine | v1.1 | 0.72 | training | 2026-02-02 01:00:00 | TensorFlow |
| 146 | churn_pred | v2.0 | 0.89 | archived | 2026-03-03 02:00:00 | XGBoost |
| 169 | spam_filter | 3.0 | 0.61 | failed | 2026-04-04 03:00:00 | sklearn |
| 192 | img_classify | v2.1-beta | 0.78 | validating | 2026-05-05 04:00:00 | pytorch |
| 215 | sentiment | 1.0.0 | 0.95 | Deployed | 2026-06-06 05:00:00 | tensorflow |
| 238 | demand_fcst | v1.0 | 0.67 | deployed | NULL | PyTorch |
| 261 | price_opt | v1.1 | 0.84 | Training | 2026-08-08 07:00:00 | TensorFlow |
| 284 | fraud_detect | v2.0 | NULL | archived | 2026-09-09 08:00:00 | XGBoost |
| 307 | rec_engine | 3.0 | 0.73 | failed | 2026-01-10 09:00:00 | sklearn |
| 330 | churn_pred | v2.1-beta | 0.9 | validating | 2026-02-11 10:00:00 | pytorch |
Expected output
| model_id | mdl_name | version | accuracy | status | train_at | framework |
|---|---|---|---|---|---|---|
| 951 | sentiment | v1.1 | 0.99 | training | 2026-02-10 13:00:00 | TensorFlow |
| 1986 | churn_pred | v2.1-beta | 0.99 | validating | 2026-02-27 10:00:00 | pytorch |
| 10002437 | sentiment | v1.1 | 0.99 | training | 2023-01-10 13:00:00 | TensorFlow |
| 2285 | price_opt | 1.0.0 | 0.95 | Deployed | 2026-06-12 23:00:00 | tensorflow |
| 2400 | img_classify | v2.1-beta | 0.9 | validating | 2026-02-17 04:00:00 | pytorch |
Worked solution and explanation
What this is really asking
This is a boundary-reading question dressed up as a model registry report. Nobody struggles with the filter itself. What separates candidates is whether 'or above' reaches the query as >=. Several models on this seed score exactly 0.90, including model_id 2400 in the preview. A query using accuracy > 0.90 runs cleanly, returns plausible rows and quietly loses every one of them. The other half is the order: the report is read strongest first, and the right rows in the wrong order still miss.
Step 1: Keep the 0.90 models in
Write the floor as accuracy >= 0.90. Those scores are stored as a plain 0.9, so the boundary is real data and not a floating-point accident. A strict comparison simply drops them.
Step 2: Return the whole model record
'Every field' means all seven columns of ml_models. Listing them by name returns the same row as SELECT *, and the output shape stays fixed if someone later adds a column to the registry.
Step 3: Put the strongest models on top
Sort by accuracy DESC. Several models share 0.99 and several share 0.90. The question says nothing about how equal scores are ordered, so any order among them is correct and no second sort key is owed.
SELECT
model_id,
mdl_name,
version,
accuracy,
status,
train_at,
framework
FROM ml_models
WHERE accuracy >= 0.90
ORDER BY accuracy DESC- Strict comparison
WHERE accuracy > 0.90reads naturally and runs without complaint, but every model sitting exactly on 0.90 disappears, model 2400 among them.- Inclusive comparison
WHERE accuracy >= 0.90keeps the boundary models, which is what 'or above' means to whoever reads the report.
Common follow-up questions
- If the ask became 'above 0.90', which models leave the result? (Tests reading the boundary both ways: the models scoring exactly 0.90 drop out.)
- How would you return only the best-scoring version of each `mdl_name`? (Moves from a plain filter to picking one row per group.)
- What breaks if `accuracy` were stored as text such as '0.9'? (Text compares character by character, so the threshold needs a numeric conversion first.)