I would like to order my select statement depends on column3 value,
something like this:
SELECT * from table
ORDER BY column1,column2,case when column3=1 then column4,column5 else
column5,column4 end
Any idea?
Regards,SYou're almost there:
SELECT * from table
ORDER BY
column1
, column2
, case when column3=1 then column4 else column5 end
, case when column3=1 then column5 else column4 end
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
.
"simon" <simon.zupan@.iware.si> wrote in message
news:YY2Je.1186$cE1.174161@.news.siol.net...
I would like to order my select statement depends on column3 value,
something like this:
SELECT * from table
ORDER BY column1,column2,case when column3=1 then column4,column5 else
column5,column4 end
Any idea?
Regards,S
Showing posts with label thisselect. Show all posts
Showing posts with label thisselect. Show all posts
Friday, March 23, 2012
Wednesday, March 21, 2012
order by
hello!
I wish to do something like this:
SELECT * FROM table ORDER BY this AND ORDER BY that
CAn it be done?
regards
RimianORDER BY cell1, cell2, cell3
that's the correct syntax. ;)|||thank you!!!
I wish to do something like this:
SELECT * FROM table ORDER BY this AND ORDER BY that
CAn it be done?
regards
RimianORDER BY cell1, cell2, cell3
that's the correct syntax. ;)|||thank you!!!
Monday, March 12, 2012
Oracle SQL: Agg. Fn. Calculation
Hi All,
I don't know if it is possible but can you do something like this:
SELECT Sum(columnX) As calc1, Sum(columnY) As calc2, (calc1 - calc2) As Difference FROM ... WHERE ... GROUP BY ...
Otherwise I'd have to do this:
SELECT Sum(columnX) As calc1, Sum(columnY) As calc2, (Sum(columnX) - Sum(columnY)) As Difference FROM ... WHERE ... GROUP BY ...
So instead of calculating the sum twice, I have to do it four times... is there any way to improve this? I've searched everything I could and I found nothing (maybe I was using the wrong keywords, but I'm pretty sure I tried thme all!)
Thanks in Advance!
WarrenOracle will do the SUM only once for each column and at the end do the calculations!
;)|||See that's what I like to hear...!
Where do I find info like that?
Thank you!
Anthony|||I learned it since Oracle 7, but wouldn't know the specific manual to refer you to.
In any case you may begin your research anywhere here:
ORACLE FAQ:
http://www.orafaq.com/
http://www.oracle-base.com/Index.php
http://www.ixora.com.au/q+a/index.html
http://www.llcsystems.com/FAQ.htm
Error Message:
http://www-rohan.sdsu.edu/doc/oracl...4625_01/toc.htm
Tips:
http://www.arikaplan.com/oracle.html
General:
http://www.csee.umbc.edu/help/
http://www.ss64.com/index.html
http://news.dcn-asu.ru/BOOKS/
http://www.daimi.au.dk/~oracle/sql/
http://www-rohan.sdsu.edu/doc/oracl...4625_01/toc.htm
Oracle 8i Database Books:
http://otn.oracle.com/pls/tahiti/tahiti.docindex
For Oracle Report Documentation:
http://www-kryo.desy.de/documents/O...n_features.html
http://dba-oracle.com/oracle_news/2004_1_21_rittman.htm
http://otn.oracle.com/documentation/reports.html
http://otn.oracle.com/products/repo...rted/index.html
:)|||And I thank you...!
Warren
I don't know if it is possible but can you do something like this:
SELECT Sum(columnX) As calc1, Sum(columnY) As calc2, (calc1 - calc2) As Difference FROM ... WHERE ... GROUP BY ...
Otherwise I'd have to do this:
SELECT Sum(columnX) As calc1, Sum(columnY) As calc2, (Sum(columnX) - Sum(columnY)) As Difference FROM ... WHERE ... GROUP BY ...
So instead of calculating the sum twice, I have to do it four times... is there any way to improve this? I've searched everything I could and I found nothing (maybe I was using the wrong keywords, but I'm pretty sure I tried thme all!)
Thanks in Advance!
WarrenOracle will do the SUM only once for each column and at the end do the calculations!
;)|||See that's what I like to hear...!
Where do I find info like that?
Thank you!
Anthony|||I learned it since Oracle 7, but wouldn't know the specific manual to refer you to.
In any case you may begin your research anywhere here:
ORACLE FAQ:
http://www.orafaq.com/
http://www.oracle-base.com/Index.php
http://www.ixora.com.au/q+a/index.html
http://www.llcsystems.com/FAQ.htm
Error Message:
http://www-rohan.sdsu.edu/doc/oracl...4625_01/toc.htm
Tips:
http://www.arikaplan.com/oracle.html
General:
http://www.csee.umbc.edu/help/
http://www.ss64.com/index.html
http://news.dcn-asu.ru/BOOKS/
http://www.daimi.au.dk/~oracle/sql/
http://www-rohan.sdsu.edu/doc/oracl...4625_01/toc.htm
Oracle 8i Database Books:
http://otn.oracle.com/pls/tahiti/tahiti.docindex
For Oracle Report Documentation:
http://www-kryo.desy.de/documents/O...n_features.html
http://dba-oracle.com/oracle_news/2004_1_21_rittman.htm
http://otn.oracle.com/documentation/reports.html
http://otn.oracle.com/products/repo...rted/index.html
:)|||And I thank you...!
Warren
Subscribe to:
Posts (Atom)