Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
I need to get the following from a table depending on the condition.count(loan_num) as 60_cnt where num_days<60count(loan_num) as 90_cnt where num_days>60Can someone help me with the query? Is it possible to do with case?Thanks,
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2010-03-17 : 09:57:56
count(case when num_days<60 then loan_num else null end) as 60_cnt ,count(case when num_days>60 then loan_num else null end) as 90_cnt------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
Lumbago
Norsk Yak Master
3271 Posts
Posted - 2010-03-17 : 10:23:45
A different method with different result but maybe it'll help you out anyway... ->
SELECT Somecolumn, 60_cnt = SUM(CASE WHEN num_days < 60 THEN 1 ELSE 0 END), 90_cnt = SUM(CASE WHEN num_days >= 60 THEN 1 ELSE 0 END)FROM mytableWHERE loan_num IS NOT NULLGROUP BY Somecolumn
- LumbagoIf the facts don't fit the theory, change the facts. Albert Einstein