SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to get count for this one
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mohan123
Constraint Violating Yak Guru

India
252 Posts

Posted - 11/28/2012 :  08:52:43  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

USA
2869 Posts

Posted - 11/28/2012 :  09:02:28  Show Profile  Reply with Quote
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)

Singapore
17584 Posts

Posted - 11/28/2012 :  09:03:01  Show Profile  Reply with Quote
sum(totalusers/246624.0)



KH
Time is always against us

Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22744 Posts

Posted - 11/29/2012 :  02:52:38  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000