Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Seventh Row Query

EasySQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is SQL Seventh Row Query. Start with the requirements and the two tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Jefferies' trade surveillance reporting needs to inspect the seventh completed execution in a deterministic sequence. Write a PostgreSQL query that returns the seventh eligible execution ordered by execution time, with the execution ID as a tie-breaker.

Requirements

  1. Consider only executions with status = 'COMPLETED'.
  2. Assign row positions using ROW_NUMBER() ordered by executed_at ASC, execution_id ASC.
  3. Return only position 7, including the execution details and trader name.
  4. Preserve the execution even when no matching trader record exists.

Schema

execution_log
ColumnTypeDescription
execution_idPKBIGINTUnique execution identifier
executed_atTIMESTAMPExecution timestamp
symbolVARCHAR(20)Traded security symbol
quantityINTEGERNumber of shares executed
trader_idINTEGERTrader identifier
statusVARCHAR(20)Execution status
traders
ColumnTypeDescription
trader_idPKINTEGERUnique trader identifier
trader_nameVARCHAR(100)Trader's name
deskVARCHAR(50)Jefferies trading desk
Tablesexecution_logtraders
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results