Quantcast
Channel: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 4871

Finding what percentage is tied to one record

$
0
0

QUESTION EDITED

Below is some sample data, The actual data is far more complex but this should be sufficient.

Some background, the data is employer listings. the request is to find out if one record accounts for 80% of employment in a given zip code. I have the following code thanks to BarryinColoradio. And it works. If I need to add a condition where it is looking at  the sum of employment by zip code (and not the entire list table) where zip code in (x,y,and z), would I add that in the second line?

Text
with total as
(select sum(employment) as total from dbo.list)
select legalname, employment/total.total as share from dbo.list,total

Viewing all articles
Browse latest Browse all 4871

Trending Articles



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