tags:

views:

55

answers:

2

I have huge data which needs to be classifed in to different groups while retrieving. Each group has a different condition. I don't want to retrieve them separately. I want to know the number of items in each group using a single sql statement.

For example, the pseudo code will be like this:

Select count(IssueID) as Issue1_Count if(condition1), 
count(IssueID) as Issue2_Count if(condition2),
count(IssueID) as Issue3_Count if(condition3)
From table1, table2, tabl3
where common_condition1 and common_Condition2;

Can somebody help me in making an Oralce query for this...

A: 

Oracle's CASE statement should help you here. Have a look at this: http://www.dba-oracle.com/t_case_sql_clause.htm

There are limits though, so I'm not 100% positive you can do exactly what you have here using them.

clifgriffin
+12  A: 

Put it like this:

SELECT 
       SUM(CASE WHEN condition1 THEN 1 ELSE 0 END) as Issue1_Count,
       SUM(CASE WHEN condition2 THEN 1 ELSE 0 END) as Issue2_Count,
       SUM(CASE WHEN condition3 THEN 1 ELSE 0 END) as Issue3_Count,
FROM 
       table1, table2, tabl3
WHERE 
       common_condition1 and common_Condition2;
Parkyprg
+1 Beat me to it!
Mark Bannister