Prices are missing on holidays. Value every trade with the most recent close_price of the same ticker on or before the trade_date (an 'as-of' join). If no earlier price exists, price_used and trade_value are NULL. trade_value = qty * price_used (qty is negative for sells), ROUND 2. Return trade_id, ticker, trade_date, price_used, trade_value. Order by trade_id.
| Column | Type |
|---|---|
| trade_id | INTEGER |
| ticker | TEXT |
| trade_date | DATE |
| qty | INTEGER |
| trade_id | ticker | trade_date | qty |
|---|---|---|---|
| 1 | ALPHA | 2026-03-03 | 10 |
| 2 | ALPHA | 2026-03-05 | -5 |
| 3 | BETA | 2026-03-03 | 20 |
| 4 | BETA | 2026-03-07 | 4 |
| 5 | ALPHA | 2026-03-06 | 2 |
| Column | Type |
|---|---|
| ticker | TEXT |
| price_date | DATE |
| close_price | REAL |
| ticker | price_date | close_price |
|---|---|---|
| ALPHA | 2026-03-02 | 100 |
| ALPHA | 2026-03-03 | 102 |
| ALPHA | 2026-03-06 | 105 |
| BETA | 2026-03-02 | 50 |
| BETA | 2026-03-04 | 52 |
| trade_id | ticker | trade_date | price_used | trade_value |
|---|---|---|---|---|
| 1 | ALPHA | 2026-03-03 | 102 | 1020 |
| 2 | ALPHA | 2026-03-05 | 102 | -510 |
| 3 | BETA | 2026-03-03 | 50 | 1000 |
| 4 | BETA | 2026-03-07 | 52 | 208 |
| 5 | ALPHA | 2026-03-06 | 105 | 210 |
Solve it in the live editor on this page — run on sample data, then submit against hidden tests.
‹ Friend Suggestions by Mutual Friends · Loan Delinquency Buckets ›
{{ totalCount }} questions in the style asked at Amazon, Microsoft, Google, Meta, Flipkart and more — {{ hardPct }}% Hard. Write SQL in a real database engine in your browser, run it on sample data, then evaluate against hidden tests.
Company tags show where this type of question is commonly reported in interviews. Questions, data and solutions are written by TechTown.
{{ cur.statement }}
No submissions yet. Press Evaluate to submit your query.
{{ solutionSql }}
{{ out.error }}
You have solved your 3 free questions — nice work! Log in (free) to unlock all 150 questions, keep your streak and appear on the leaderboard.