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

ml_models: 10 of 200 rows
model_idmdl_nameversionaccuracystatustrain_atframework
123rec_enginev1.10.72training2026-02-02 01:00:00TensorFlow
146churn_predv2.00.89archived2026-03-03 02:00:00XGBoost
169spam_filter3.00.61failed2026-04-04 03:00:00sklearn
192img_classifyv2.1-beta0.78validating2026-05-05 04:00:00pytorch
215sentiment1.0.00.95Deployed2026-06-06 05:00:00tensorflow
238demand_fcstv1.00.67deployedNULLPyTorch
261price_optv1.10.84Training2026-08-08 07:00:00TensorFlow
284fraud_detectv2.0NULLarchived2026-09-09 08:00:00XGBoost
307rec_engine3.00.73failed2026-01-10 09:00:00sklearn
330churn_predv2.1-beta0.9validating2026-02-11 10:00:00pytorch

Expected output

First 5 of 44 rows
model_idmdl_nameversionaccuracystatustrain_atframework
951sentimentv1.10.99training2026-02-10 13:00:00TensorFlow
1986churn_predv2.1-beta0.99validating2026-02-27 10:00:00pytorch
10002437sentimentv1.10.99training2023-01-10 13:00:00TensorFlow
2285price_opt1.0.00.95Deployed2026-06-12 23:00:00tensorflow
2400img_classifyv2.1-beta0.9validating2026-02-17 04:00:00pytorch

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.

Models at or above 0.90, strongest first
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.90 reads naturally and runs without complaint, but every model sitting exactly on 0.90 disappears, model 2400 among them.
Inclusive comparison
WHERE accuracy >= 0.90 keeps the boundary models, which is what 'or above' means to whoever reads the report.

Common follow-up questions