Re: conditional 'order by'

  • From: Daniel Fink <daniel.fink@xxxxxxxxxxxxxx>
  • To: eugene.pipko@xxxxxxxxxxxx
  • Date: Fri, 19 Dec 2008 10:13:47 -0700

Eugene,

Is this code part of the data or a parameter passed in?

You can use CASE in your order by (you can also use a subquery), but without understanding more about the data and query, it is hard to construct an example.

At least...I don't understand the query...but I'm not the sharpest spoon in the SQL drawer...

Regards,
Daniel Fink

--
Daniel Fink

OptimalDBA.com - Oracle Performance, Diagnosis, Data Recovery and Training

OptimalDBA    http://www.optimaldba.com
Oracle Blog   http://optimaldba.blogspot.com

Lost Data?    http://www.ora600.be/


Eugene Pipko wrote:

Hi all,

I have a query that needs to be ordered by based on the second letter of the code passed in it.

For instance if the code is '9F9Q' then I'd order by 'F' , then by 'H', then by any other.

If the code is '7H7Q' then I'd order by 'H', then by 'F', then by any other.

I know that I can do it in 2 steps, but is it possible to do in one sql statement?

Select ...

From ...

Where ....

If substr(code,2,1)='F' then

                Order by decode(code,'F',0,'H',1,2);

Elsif substr(code,2,1)='H' then

                Order by decode(code,'H',0,'F',1,2);

End if;

Thanks,

Eugene

P  Please consider the environment before printing this e-mail.



--
Daniel Fink

OptimalDBA.com - Oracle Performance, Diagnosis, Data Recovery and Training

OptimalDBA    http://www.optimaldba.com
Oracle Blog   http://optimaldba.blogspot.com

Lost Data?    http://www.ora600.be/

Other related posts: