SQL command [message #19151] |
Sun, 03 March 2002 21:37 |
bala_60
Messages: 3 Registered: March 2002
|
Junior Member |
|
|
Dear Friends,
Can any one tell me how to get the out put from stocks
in this format
Symbol company date1 date2 date3 date4
(where date1...date4) should show the trade_date
for the last 5 dates
|
|
|
Re: SQL command [message #19170 is a reply to message #19151] |
Mon, 04 March 2002 04:11 |
pratap kumar tripathy
Messages: 660 Registered: January 2002
|
Senior Member |
|
|
select distinct symbol,
company,
lag(trade_date,4) over(order by trade_date) as trade4,
lag(trade_date,3) over(order by trade_date) as trade3,
lag(trade_date,2) over(order by trade_date) as trade2,
lag(trade_date,1) over(order by trade_date) as trade1,
trade_date
from stocks s1
) s1
where trade_date=(select max(trade_date) from stocks s2 where s1.symbol=s2.symbol and s1.company=s2.company)
|
|
|