Skip to content

Commit d5abc63

Browse files
Update 180. Consecutive Numbers.sql
Co-Authored-By: Antim-IWP <203163676+Antim-IWP@users.noreply.github.com>
1 parent 85ee08b commit d5abc63

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

LeetCode SQL 50 Solution/180. Consecutive Numbers.sql

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,24 @@ It then filters out rows where the current value is the same as both the previou
110110
Final Output:
111111
The final result is a list of distinct numbers that appear consecutively in the Logs table.
112112
"""
113+
114+
115+
# Write your MySQL query statement below
116+
# Write your MySQL query statement below
117+
WITH
118+
T AS (SELECT DISTINCT product_id FROM Products),
119+
P AS (
120+
SELECT product_id, new_price AS price
121+
FROM Products
122+
WHERE
123+
(product_id, change_date) IN (
124+
SELECT product_id, MAX(change_date) AS change_date
125+
FROM Products
126+
WHERE change_date <= '2019-08-16'
127+
GROUP BY 1
128+
)
129+
)
130+
SELECT product_id, IFNULL(price, 10) AS price
131+
FROM
132+
T
133+
LEFT JOIN P USING (product_id);

0 commit comments

Comments
 (0)