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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-04-14 : 22:04:24
|
| Fraggle27 writes "Hello.ive got the folling table...tableAtransaction_idteam_namepriority_flagand 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 Percentagefrom tableAgroup by teamHTH-------------------------------------------------------------- |
 |
|
|
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 Percentagefrom tableAgroup 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 Percentagefrom tableAgroup by team------------------------GENERAL-ly speaking... |
 |
|
|
|
|
|