Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
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
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
Build my plan
Walk Through a Given SQL Query
00:00
5 left

Walk Through a Given SQL Query

MediumSQL · PostgreSQL

Problem

At LSEG, a software engineer is reviewing a query that a teammate wrote to summarize the previous day's trading activity per instrument. The relevant tables are trades (trade_id, instrument_id, trade_ts, quantity, price, venue), instruments (instrument_id, symbol, currency), and corporate_actions (action_id, instrument_id, action_type, effective_date), where an instrument can have zero, one, or several corporate actions on record.

SELECT i.symbol,
       DATE(t.trade_ts) AS trade_date,
       SUM(t.quantity) AS total_volume,
       AVG(t.price) AS avg_price
FROM trades t
JOIN instruments i ON i.instrument_id = t.instrument_id
LEFT JOIN corporate_actions ca ON ca.instrument_id = t.instrument_id
WHERE t.trade_ts >= CURRENT_DATE - 1
GROUP BY i.symbol, DATE(t.trade_ts)
ORDER BY total_volume DESC;

Walk through what this query does, and explain how you would verify whether its output is actually correct.

Output

  1. Return one row per instrument symbol and previous calendar date, with symbol, trade_date, total_volume, and avg_price.
  2. Include only trades from the previous calendar day, exclude instruments without a matching instrument record, and order by total_volume descending.

Schema

trades
ColumnTypeDescription
trade_idPKINTUnique trade identifier
instrument_idINTReferenced instrument identifier
trade_tsTIMESTAMPTrade execution timestamp
quantityNUMERIC(18,4)Executed quantity
priceNUMERIC(18,6)Execution price
venueVARCHAR(30)Trading venue
instruments
ColumnTypeDescription
instrument_idPKINTUnique instrument identifier
symbolVARCHAR(20)Instrument symbol
currencyVARCHAR(3)Trading currency
corporate_actions
ColumnTypeDescription
action_idPKINTUnique corporate action identifier
instrument_idINTAffected instrument identifier
action_typeVARCHAR(30)Corporate action type
effective_dateDATEEffective date of the action
Tablestradesinstrumentscorporate_actions
Interviewer

Your question is Walk Through a Given SQL Query. Start with the requirements and the three tables in the Question tab.

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.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.