Last active
August 8, 2021 05:54
-
-
Save monmonmon/931bbbf12578761155fb95dfb857dbf3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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