Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Group by case

Status
Not open for further replies.

mjuell

Programmer
Jun 26, 2003
17
NO
How do i group by a case in oracle. ?
In sybase my statement looks like this.

select case when c.cust_unit_number is null then 'private' else 'business' end,count(distinct a.cust_id_resp)
from cm.account a, cm.customer c
where a.info_is_deleted = 'N'
and a.foreign_account is not null
and a.cust_id_resp = c.cust_id
and c.info_is_deleted = 'N'
group by case when c.cust_unit_number is null then 'privat' else 'bedrift' end
 
MJuell,

I just successfully ran a query that is syntactically similar to yours:
Code:
select case when salary > 1000 then 'Hi Pay' else 'Lo Pay' end Grade, count(*) HowMany
from s_emp
group by case when salary > 1000 then 'Hi Pay' else 'Lo Pay' end
/

GRADE     HOWMANY
------ ----------
Hi Pay         18
Lo Pay          7

2 rows selected.

Does this resolve your problem?

[santa]Mufasa
(aka Dave of Sandy, Utah, USA @ 11:07 (06May04) UTC (aka "GMT" and "Zulu"), 04:07 (06May04) Mountain Time)
 
Hi ,

You guys have a small CASE, so things look good.

I have few queries which use very big CASE, around 9 to 10 conditions, but not a group by. If at all I have to use group by in such cases, the query will look like a mess.

Any suggessions ?

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top