Skip to content

Commit

Permalink
Create change-null-values-in-a-table-to-the-previous-value.sql
Browse files Browse the repository at this point in the history
  • Loading branch information
kamyu104 authored Aug 29, 2022
1 parent c6a82d5 commit 77991fe
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions MySQL/change-null-values-in-a-table-to-the-previous-value.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Time: O(nlogn)
# Space: O(n)

WITH rn_cte AS (
SELECT id, drink, ROW_NUMBER() OVER () AS rn
FROM CoffeeShop
),
group_cte AS (
SELECT id, drink, rn, SUM(NOT ISNULL(drink)) OVER (ORDER BY rn) AS group_id
FROM rn_cte
)

SELECT id, MAX(drink) OVER (PARTITION BY group_id) AS drink
FROM group_cte
ORDER BY rn;

0 comments on commit 77991fe

Please sign in to comment.