Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Trying to calculate a relative percentage over a set

$
0
0

Here''s the SQL that I came up with (it doesn't work)

;with cte as (select COMPANY as COMPANY, [INDEX MARKET CAP] as IndexCap, Count ([INDEX MARKET CAP]) as CountOfRates
from [Test_DB].[dbo].[S&P_Emerging_SmallCap_(US_Dollar)]
group by COMPANY, [INDEX MARKET CAP])
select *, CAST(CountOfRates*100.0 / SUM(CountOfRates) OVER()  as Decimal(14,14)) as [%]
FROM cte

The problem is that the % field never changes!! I want to take each record of [Index Market Cap] and divide by the aggregate of the [Index Market Cap].  I'm sure this can be done with a CTE, but I'm far from a CTE expert, so I'm not sure how to pull this off.

Please offer guidance


Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>