Top 10 Model Accuracies

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
Asked in
ESPN

Problem

We keep a registry of ML models and want a leaderboard of the ten most accurate, most accurate first, showing each model's name and its accuracy. When two models are equally accurate, the one that was registered first ranks ahead.

Top ten model performance.

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 10 rows
model_idmdl_nameaccuracy
951sentiment0.99
1986churn_pred0.99
10002437sentiment0.99
10002482churn_pred0.99
767sentiment0.98

Worked solution and explanation

Why this problem exists in real interviews

Ranking ML models by accuracy is a simple top-N pattern that verifies you can order by a numeric metric and apply LIMIT.


Break down the requirements

Step 1: Order by accuracy

Order all rows in ml_models by accuracy descending so the highest-accuracy models come first.

Step 2: Limit to 10

Add model_id ASC as a deterministic tiebreaker so equal-accuracy models have a stable, reproducible order.


The solution

Simple ranking by accuracy metric
SELECT model_id, mdl_name, accuracy
FROM ml_models
ORDER BY accuracy DESC, model_id ASC
LIMIT 10

Common follow-up questions