Re: Q: SQL output order by keys possible?

From: David J Roth <droth_at_adaptron.com>
Date: 1996/10/11
Message-ID: <325E278D.5F5C_at_adaptron.com>#1/1


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 EMP,SALAR from ALL_EMPS
where SALAR <= 10000
order by decode(DEPT,'PR','AAAA',DEPT);

Dave Roth Received on Fri Oct 11 1996 - 00:00:00 CEST

Original text of this message