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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Percentage of customers number by region

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 name
The 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:

select
r.Region_NM,
dt.Client_Percent
from
(select Region_CD, count(*) / (select count(*) from Client) as Client_Percent from Client group by Region_CD)dt
join 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.
Go to Top of Page

Aloz
Starting Member

2 Posts

Posted - 2010-10-14 : 14:55:49
WebFred, Thanks a lot. It worked fast and correctly.
Go to Top of Page

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.
Go to Top of Page
   

- Advertisement -