Dear Experts,I've the following three tables prices, cData, securities. I need to get lowest ratio from different sectors. #Prices TableTicker date_ close_---------------- ---------- --------ABBANK 2010-01-02 15.00ABBANK 2010-01-03 16.00ABBANK 2010-01-04 13.00AC 2010-01-02 10.00AC 2010-01-03 15.00AC 2010-01-04 8.00AG 2010-01-02 30.00AG 2010-01-03 40.00AG 2010-01-04 20.00ALARA 2010-01-02 6.00ALARA 2010-01-03 7.00ALARA 2010-01-04 10.00AT 2010-01-02 10.00AT 2010-01-03 9.00AT 2010-01-04 8.00BASIA 2010-01-02 20.00BASIA 2010-01-03 30.00BASIA 2010-01-04 50.00#securities tableTicker name sector---------------- -----------------------ABBANK abbank BankAC AC BankAG ag RetailALARA alara ITAT at ITBASIA basia Retail#cData tableTicker ShareNums NprofitABBANK 100.00 10.00AC 200.00 300.00AG 600.00 300.00ALARA 90.00 15.00AT 50.00 500.00BASIA 80.00 20.00
i have created SP that gives follwing result: Ticker sector Latest PE---------------- --------------------------------AC Bank 2010-01-04 5.33ABBANK Bank 2010-01-04 130.0AT IT 2010-01-04 0.80ALARA IT 2010-01-04 60.0AG Retail 2010-01-04 40.0BASIA Retail 2010-01-04 200.0I actually need the following result:Ticker sector Latest PE---------------- --------------------------------AC Bank 2010-01-04 5.33AT IT 2010-01-04 0.80AG Retail 2010-01-04 40.0
Thx in advance for your help. quote:
StoredProc:select c.Ticker, s.sector, l.Latest, (c.ShareNums * p.Close_)/(c.NProfit) as PE from cData c join ( select Ticker, max(date_) as Latest from prices group by Ticker) l on c.Ticker=l.Ticker join prices p on l.Ticker=p.Ticker and l.latest=p.date_join securities son c.ticker=s.tickerorder by s.sector;