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
 How to get count for this one

Author  Topic 

mohan123
Constraint Violating Yak Guru

252 Posts

Posted - 2012-11-28 : 08:52:43
select * ,
case when DimConditionDefinitionId =1 then sum(totalusers/246624)
when DimConditionDefinitionId =2 then sum(totalusers/246624)
when DimConditionDefinitionId =3 then sum(totalusers/246624)
when DimConditionDefinitionId =4 then sum(totalusers/246624)
else 0 end as populationcount
from dbo.pop_fact group by DimConditionDefinitionId,FactPopulationDefinitionId,totalusers

When i executing these query i am getting population count as '0'
Actually i need to get sum values for all conditions suggest me

P.V.P.MOhan

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2012-11-28 : 09:02:28
select*
,SUM (CASE WHEN DimConditionDefinitionId between 1 and 4
THEN totalusers
ELSE 0
END) /246624.0

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-11-28 : 09:03:01
[code] sum(totalusers/246624.0)[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2012-11-29 : 02:52:38
quote:
Originally posted by jimf

select*
,SUM (CASE WHEN DimConditionDefinitionId between 1 and 4
THEN totalusers
ELSE 0
END) /246624.0

Jim

Everyday I learn something that somebody else already knew


Also list out required columns and include them in GROUP BY clause too

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -