Re: Q: SQL output order by keys possible?

From: Chuck Hamilton <chuckh_at_dvol.com>
Date: 1996/10/09
Message-ID: <325da817.2825342_at_n5.gbso.net>#1/1


f91-gal_at_nada.kth.se (Göran Alterland) wrote:

>I've run into this snag. Having a table, is there any way to
>sort the output in anything but ascending/descending order?
>
>Say you've got
>
>select EMP,SALAR from ALL_EMPS
>where SALAR <= 10000
>order by DEPT
>
>where EMP,SALAR and DEPT are all columns in the ALL_EMPS table.
>This will group together all the empolyees in all departments
>before showing the answer.
>
>But what what I'd really like to do is to output a given department
>first, something along the lines of
>
>select EMP,SALAR from ALL_EMPS
>where SALAR <= 10000
>order by DEPT where DEPT like 'PR' first
>
>This doesn't work of course. Is there any way to do this? The
>best I can come up with on my own are two queries like this:
>
>select EMP,SALAR from ALL_EMPS
>where SALAR <= 10000
>and DEPT like 'PR'
>
>select EMP,SALAR from ALL_EMPS
>where SALAR <= 10000
>and DEPT NOT like 'PR'
>
>However, I don't really like having two queries. Am I missing
>something terribly obvious here?
>
>TIA,
>/Göran

Try this...

select DEPT,EMP,SALAR from ALL_EMPS
where SALAR <= 10000
order by decode(DEPT,'PR',0,1)

--
Chuck Hamilton
chuckh_at_dvol.com

This message delivered by electronic sled dogs. WOOF!
Received on Wed Oct 09 1996 - 00:00:00 CEST

Original text of this message