| Please help me to write a SQL [message #572370] |
Tue, 11 December 2012 04:26  |
 |
pvsatish.etl
Messages: 2 Registered: December 2012 Location: Banglore
|
Junior Member |
|
|
Hi I have data like below
ITEM price day
-----------------
Item1 10 day1
Item1 20 day2
Item1 20 day3
Item1 20 day4
item1 30 day5
item1 10 day6
item1 40 day7
item1 40 day8
Requirement:
If price of item is changed on next day i need to capture that info else not required.
The item price on day2,3,4 is same so I need only day2 info.
The item price on day1 and 6 is same bat I need both because in beet 1 and 6 price got changed.
My out put should be like below
ITEM price day
-----------------
Item1 10 day1
Item1 20 day2
item1 30 day5
item1 10 day6
item1 40 day7
Can any one help me to write the SQL for above requirement.
Thanks in Advance ...........
[Updated on: Tue, 11 December 2012 04:37] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
| Re: Please help me to write a SQL [message #572721 is a reply to message #572551] |
Sun, 16 December 2012 12:41   |
guesthyd
Messages: 8 Registered: April 2012
|
Junior Member |
|
|
select a.item,a.day,a.price,a.previous_price
from (
select
item,price,day,lag(price,1) over (order by day) as previous_price
from item_price)a
where a.price<>a.previous_price
or a.previous_price is null
|
|
|
|
|
|