Home » RDBMS Server » Server Administration » Need some special output from select (order, decode, ...)
Need some special output from select (order, decode, ...) [message #372065] Mon, 08 January 2001 15:23 Go to next message
X Men
Messages: 1
Registered: January 2001
Junior Member
Hello,

I have a table

sql> select * from important;
+------+-------+
| prio | value |
+------+-------+
| 3 | x3 |
| 1 | x1 |
| 2 | x2 |
| 0 | x0 |
+------+-------+
4 rows in set (0.00 sec)

sql> select * from important order by prio;
+------+-------+
| prio | value |
+------+-------+
| 0 | x0 |
| 1 | x1 |
| 2 | x2 |
| 3 | x3 |
+------+-------+
4 rows in set (0.00 sec)

sql>

Since we define priority 0 as the lowest one,
I want the output as
+------+-------+
| prio | value |
+------+-------+
| 1 | x1 |
| 2 | x2 |
| 3 | x3 |
| 0 | x0 |
+------+-------+

Could some one help me about how to get this output?

Thanks

S.DONG
Re: Need some special output from select (order, decode, ...) [message #372072 is a reply to message #372065] Tue, 09 January 2001 02:11 Go to previous messageGo to next message
Tittom
Messages: 15
Registered: November 2000
Junior Member
If the prio is set to NULL instead of 0, the order by prio should give you the result you are expecting.

I hope this helps. If not, I think we could work out a sql query...

Tittom
Re: Need some special output from select (order, decode, ...) [message #372084 is a reply to message #372065] Tue, 09 January 2001 09:07 Go to previous message
me
Messages: 66
Registered: August 2000
Member
select decode(prio,0,2,1) order_by, prio, value
from important
order by order_by, prio
Previous Topic: Looking for a simple way to clone data (intra table).
Next Topic: SQLPLUS format
Goto Forum:
  


Current Time: Sat May 18 02:12:44 CDT 2024