Reputation: 23
I have a following sql query which returns me index prices for 2 different indices.
select *
from INDICEPRICEHISTORY
PIVOT (MAX(PRICE)
FOR TICKER IN
([OMXH25],[UX])
)
as Pricelist
ORDER BY EOD DESC;
Query returns:
EOD OMXH25 UX
2015-10-10 3157.20 843.48
2015-10-09 3157.20 843.48
2015-10-08 3138.35 837.37
2015-10-07 3138.47 835.43
Is there any way to normalize this data in sql query for some base point, for example 2015-10-07 to be 100 points and other values are related to that. Mockup below:
EOD OMXH25 UX
2015-10-10 100.5967876 100.9635756
2015-10-09 100.5967876 100.9635756
2015-10-08 99.99617648 100.2322157
2015-10-07 100 100
Idea is to make these two (or more) columns comparable in a line chart.
Any suggestions? Is this even possible in SQL? I'm using MSSQL 2014.
Thank you!
Upvotes: 1
Views: 386
Reputation: 35790
Here is an example:
;with r as(your current query),
t as(select top 1 * from r order by eod)
select r.eod,
r.omxh25 * 100 / t.omxh25 as omxh25,
r.ux * 100 / t.ux as ux
from r
cross join t
Upvotes: 3