Output  hist_qry5.sql

Appendix A: SQL Scripts for Sample Queries

SQL

The following script contains the SQL statements for this query.

-- Calculate the value of the S&P500 and Russell 2000 index
-- for a specified day using unadjusted prices and the index composition
-- of the 2 indexes (see appendix for spec) on the specified day.

commit
;

Select ii.INDEX_NAME, AVG(sh.CLOSE_PRICE) as AVERAGE_CLOSE_PRICE
FROM MARKET_INDEX AS ii 
inner join INDEX_CMPSTN AS ic
	on ii.MARKET_INDEX_ID = ic.MARKET_INDEX_ID 
inner join STOCK_HISTORY AS sh
on ic.INSTRUMENT_ID = sh.INSTRUMENT_ID
and sh.TRADE_DATE = '2005-03-03'
WHERE ii.INDEX_NAME in ('S&P 500','Russell 2000') 
GROUP BY
ii.INDEX_NAME
;




Copyright © 2005. Sybase Inc. All rights reserved. hist_qry5.sql

View this book as PDF