Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
-- SQLクイズへの回答 https://github.com/neumann-tokyo/sql-quiz/blob/main/store/question.md
SELECT r.item_name,
r.weeknum,
COALESCE(s.price, 0) AS lastweek_price,
r.price,
CASE
WHEN COALESCE(s.price, 0) < r.price THEN '/'
WHEN COALESCE(s.price, 0) > r.price THEN '\'
ELSE '='
END AS mark
FROM reports r
LEFT JOIN reports s
ON r.item_name = s.item_name
AND r.weeknum - 1 = s.weeknum
ORDER BY r.item_name,
r.weeknum;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment