Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Aloz
Starting Member
2 Posts |
Posted - 2010-10-12 : 19:03:53
|
To calculate the percentage of customers by region, from the following tables:Client (Client_id, Region_Cd, ...)Region (Region_Cd, Region_Nm, ...) where Region_Nm is the region nameThe result should be:Region_Nm, Client_Percent ( 1 row for each region where Cliente_Percent = [Client Count in a region / Total of Clients] )Thanks in advance,ALF. |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-10-13 : 07:57:37
|
Try:selectr.Region_NM,dt.Client_Percent from(select Region_CD, count(*) / (select count(*) from Client) as Client_Percent from Client group by Region_CD)dtjoin Region r on r.Region_CD = dt.Region_CD No, you're never too old to Yak'n'Roll if you're too young to die. |
|
|
Aloz
Starting Member
2 Posts |
Posted - 2010-10-14 : 14:55:49
|
WebFred, Thanks a lot. It worked fast and correctly. |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-10-14 : 16:57:29
|
welcome No, you're never too old to Yak'n'Roll if you're too young to die. |
|
|
|
|
|