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 >= DATE '2026-10-07' - 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.
symbol, trade_date, total_volume, and avg_price.total_volume descending.Note: Treat DATE '2026-10-07' as today's date.
| Column | Type | Description |
|---|---|---|
| trade_idPK | INT | Unique trade identifier |
| instrument_id | INT | Referenced instrument identifier |
| trade_ts | TIMESTAMP | Trade execution timestamp |
| quantity | NUMERIC(18,4) | Executed quantity |
| price | NUMERIC(18,6) | Execution price |
| venue | VARCHAR(30) | Trading venue |
| Column | Type | Description |
|---|---|---|
| instrument_idPK | INT | Unique instrument identifier |
| symbol | VARCHAR(20) | Instrument symbol |
| currency | VARCHAR(3) | Trading currency |
| Column | Type | Description |
|---|---|---|
| action_idPK | INT | Unique corporate action identifier |
| instrument_id | INT | Affected instrument identifier |
| action_type | VARCHAR(30) | Corporate action type |
| effective_date | DATE | Effective date of the action |