I'm using the Superstore_test dataset here: https://www.kaggle.com/blurredmachine/superstore-time-series-dataset
I want to make a column that shows the sales of the next row down. I put this query in and I get very odd results where some rows are matched to the sales of the next row, and some aren't. The weird thing is that if I take the subquery and use it by itself, it returns a table with next_sales column lined-up perfectly. Can someone please explain this conceptually?
Query:
UPDATE Superstore_test
SET next_sales = subquery.next_sales
FROM (
SELECT order_id, sales, LEAD(sales) OVER (ORDER BY order_id asc) AS next_sales
FROM Superstore_test
) AS subquery
WHERE subquery.sales = Superstore_test.sales
;
I want to make a new column that shows the sales of the next row down. I get this though:
sales | next_sales |
---|---|
299.94 | 25.76 |
25.76 | 52.59 |
271.9 | 45.84 |
45.84 | 9.82 |
9.82 | 998.82 |
93.36 | 66.97600000000001 |
541.24 | 106.32 |
106.32 | 1323.8999999999999 |
1323.8999999999999 | 299.94 |