Monday, April 17, 2006
Thursday, April 06, 2006
A interest query
we have a table items which miss some price for some weeks
we want to have a query to replace the missed price with last available price
SELECT i_item,
i_week,
i_price,
SUM(i_price) over(PARTITION BY new_price) new_price2
FROM (
SELECT i.item AS i_item,
i.week AS i_week,
i.price AS i_price,
SUM(i.price) over(ORDER BY i.item, i.week) new_price
FROM items i)
ORDER BY 1,
2
Week | Item | Price |
1 | 1 | 8 |
2 | 1 | null |
3 | 1 | null |
4 | 1 | 7 |
1 | 2 | 6 |
2 | 2 | 3 |
3 | 2 | null |
1 | 3 | 2 |
2 | 3 | null |
3 | 3 | 4 |
4 | 3 | 2 |
5 | 3 | null |
we want to have a query to replace the missed price with last available price
SELECT i_item,
i_week,
i_price,
SUM(i_price) over(PARTITION BY new_price) new_price2
FROM (
SELECT i.item AS i_item,
i.week AS i_week,
i.price AS i_price,
SUM(i.price) over(ORDER BY i.item, i.week) new_price
FROM items i)
ORDER BY 1,
2
Subscribe to:
Posts (Atom)