Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Trending in AI
Hot
Agentic AI EngineerForward-Deployed EngineerGenAI EngineerAI Architect
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Start free
Rank January 2025 SQL Query Metrics
00:00
5 left

Rank January 2025 SQL Query Metrics

MediumSQL · PostgreSQL

Problem

How do you evaluate your performance in SQL?

Using PostgreSQL, write a query that evaluates active SQL queries executed during January 2025. Include queries with no matching executions so their performance metrics remain visible.

Output

  1. One row per active query, with query_name, owner_team, run_count, avg_duration_ms, p95_duration_ms, success_rate, and performance_rank.
  2. Include queries without executions with NULL metric values where appropriate.
  3. Rank measured queries by average duration ascending, place unmeasured queries after measured queries, and sort by rank then query_name.

Output details

  • Treat January as 2025-01-01 00:00:00 inclusive through 2025-02-01 00:00:00 exclusive.
  • Round avg_duration_ms, p95_duration_ms, and success_rate to two decimal places, expressing success_rate as a percentage.
  • Calculate p95_duration_ms using the continuous 95th percentile of non-NULL duration_ms values.
  • Count executions using non-NULL run_id values and return NULL for success_rate when that count is zero.
  • Assign competition ranks by ascending avg_duration_ms, leaving performance_rank NULL when average duration is NULL.
  • Place NULL ranks last.

Schema

sql_queries
ColumnTypeDescription
query_idPKINTUnique identifier for a SQL query
query_nameVARCHAR(100)Human-readable query name
owner_teamVARCHAR(80)Team responsible for the query
is_activeBOOLEANWhether the query is currently active
sql_query_runs
ColumnTypeDescription
run_idPKINTUnique identifier for an execution
query_idINTExecuted query identifier
executed_atTIMESTAMPExecution timestamp
duration_msINTExecution duration in milliseconds
statusVARCHAR(20)Execution result status
Tablessql_queriessql_query_runs
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the two tables are in the Question tab.

Sign up free to run or submit. Log in
CodePostgreSQL
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 1
Run your query to see results here.