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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 count divded by ( count on same field with restriction)

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-04-14 : 22:04:24
Fraggle27 writes "Hello.

ive got the folling table...

tableA
transaction_id
team_name
priority_flag

and i want to select...

percentage of transactions for a team where priority flag = high.

so i need to divide the total number of transactions for a team by the total number of transactions for the team where the priority flag is high.

what do you thing? doable? maybee a case?

thanks for your time,

Jez."

Nazim
A custom title

1408 Posts

Posted - 2002-04-15 : 00:18:00
yeah a case will help.


select team, count(1)/sum(case priority_flag when 'high' then 1 else 0 end) as Percentage
from tableA
group by team

HTH

--------------------------------------------------------------
Go to Top of Page

AjarnMark
SQL Slashing Gunting Master

3246 Posts

Posted - 2002-04-15 : 20:09:47
quote:

select team, count(1)/sum(case priority_flag when 'high' then 1 else 0 end) as Percentage
from tableA
group by team



Isn't this upside-down? I know it's what the original post said, but this will return values of 100% and higher. I think it should be

select team, sum(case priority_flag when 'high' then 1 else 0 end) / count(1) as Percentage
from tableA
group by team


------------------------
GENERAL-ly speaking...
Go to Top of Page
   

- Advertisement -