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 |
akpaga
Constraint Violating Yak Guru
331 Posts |
Posted - 2012-05-16 : 16:54:55
|
HiI am having a strange problem as belowI have table in the following way:Customer_no Purchase_Status StaTus_date1 yes 09/09/201223 yes 10/10/20124 yes 09/23/2012From The above scenarioI want to calculate Percent for total number of customers whose purchase status is 'Yes' for the month of September to the total number of customersw hich is 2/4 but when i pass the Status_date between '09/01/2012' and '09/30/2012'I am only getting 2/2..How cna i achive it for 2/4..Please help... |
|
influent
Constraint Violating Yak Guru
367 Posts |
Posted - 2012-05-16 : 17:00:23
|
Something like this will give you both numbers:select count(*), (select TotalCustomers = COUNT(DISTINCT Customer_no) from thetable)from thetablewhere StaTus_date between '09/01/2012' and '09/30/2012' and Purchase_Status = 'yes' |
 |
|
akpaga
Constraint Violating Yak Guru
331 Posts |
Posted - 2012-05-16 : 17:54:44
|
quote: Originally posted by influent Something like this will give you both numbers:select count(*), (select TotalCustomers = COUNT(DISTINCT Customer_no) from thetable)from thetablewhere StaTus_date between '09/01/2012' and '09/30/2012' and Purchase_Status = 'yes'
Thank You influent..it worked.. |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-05-16 : 20:26:21
|
isnt this enough?select sum(case when StaTus_date between '09/01/2012' and '09/30/2012' then 1 else 0 end) * 1.0/count(*) as percentagecountfrom thetablewhere Purchase_Status = 'yes' ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|