Home » SQL & PL/SQL » SQL & PL/SQL » SQL command
SQL command [message #19151] Sun, 03 March 2002 21:37 Go to next message
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 Go to previous message
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)
Previous Topic: drop user username cascade just hangs..
Next Topic: Executing a Script from within a Procedure
Goto Forum:
  


Current Time: Thu Mar 28 19:53:40 CDT 2024