medium · ~12 min
Market analytics needs a daily price-movement view built from stock_prices, which stores daily closing prices across multiple stock tickers.
stock_prices
Write a query that shows each trading day alongside the neighboring closing prices for the same ticker:
(ticker, date)
prev_price
date
next_price
NULL
ticker
price
Input contract: (ticker, date) is unique and non-null; date is an ISO YYYY-MM-DD string; price is a non-null float. The table contains histories for one or more tickers.
YYYY-MM-DD