Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3aab10e

Browse files
committed
이예진: [SQL] Product Price at a Given Date_241126
1 parent 0b34228 commit 3aab10e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
SELECT
2+
DISTINCT p.product_id,
3+
CASE
4+
WHEN distinct_p.product_id IS NULL THEN 10
5+
ELSE p.new_price
6+
END AS price
7+
FROM Products p
8+
LEFT JOIN (
9+
SELECT product_id, MAX(change_date) change_date
10+
FROM Products
11+
WHERE change_date < '2019年08月17日'
12+
GROUP BY product_id
13+
) sub
14+
ON p.product_id = sub.product_id AND p.change_date = sub.change_date
15+
LEFT JOIN (
16+
SELECT DISTINCT product_id
17+
FROM Products
18+
WHERE change_date < '2019年08月17日'
19+
) distinct_p
20+
ON p.product_id = distinct_p.product_id
21+
WHERE sub.change_date IS NOT NULL OR distinct_p.product_id IS NULL

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /