Semi-structured & modern warehouse SQL
Exercise · SQL & Querying

Predict, then run it

Predict the output

shops(s) = north, south. sales(s, item, n) per shop. Each shop's top two sellers — LATERAL, so the subquery sees the current shop:

SELECT sh.s, t.item FROM shops sh, LATERAL (SELECT item, n FROM sales sa WHERE sa.s = sh.s ORDER BY n DESC LIMIT 2) t ORDER BY sh.s, t.n DESC;

Predict the exact output.