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 2005 Forums
 Transact-SQL (2005)
 Select some column with another condition. Help

Author  Topic 

txk2601
Starting Member

19 Posts

Posted - 2009-04-09 : 02:39:38
Hi all. I have a table with following columns.

AutoID | GroupID | ServiceCode | Status

I wan't select Count(AutoID) as MT with No condition; Count(Distinct GroupID) with GroupID != 0 and Count(AutoID as Cdr with Status = 1000.
All is group by ServiceCode. I don't know write in one Select query. Please help me. Thanks alot

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-04-09 : 02:53:02
[code]
select
ServiceCode,
Count(AutoID) as MT ,
Count(Distinct case when GroupID <> 0 then GroupID end ) ,
Count(case when Status = 1000 then AutoID end) as Cdr
from
your_table
group by
ServiceCode
[/code]


Madhivanan

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

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-04-09 : 02:54:33
SELECT ServiceCode, COUNT(AutoID) AS MT,
COUNT(DISTINCT CASE WHEN GroupID <> 0 THEN GroupID ELSE NULL END),
SUM(CASE WHEN Status = 1000 THEN 1 ELSE 0 END) AS Cdr
FROM Table1
GROUP BY ServiceCode



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-04-09 : 02:55:02




E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
   

- Advertisement -