测试: create table tb_1 (a number,b varchar(10));insert into tb_1 values(1, 'a'); insert into tb_1 values(1 , 'g'); insert into tb_1 values(2 , 'c'); insert into tb_1 values(3 ,'t'); insert into tb_1 values(4 ,'8'); insert into tb_1 values(0 ,'9');select * from tb_1 order by decode(a,1,1,2),a; /* A B ---------- ---------- 1 a 1 g 0 9 2 c 3 t 4 8已选择6行。 */
to bzszp(www.bzszp.533.net) : 你的做法有问题,应该是这样的select * from tb_1 where a=1 UNION ALL (SELECT * FROM (select * from tb_1 where a<>1 order by a)) / A B ---------- ---------- 1 a 1 g 0 9 2 c 3 t 4 86 rows selected
create table tb_1 (a number,b varchar(10));insert into tb_1 values(1, 'a');
insert into tb_1 values(1 , 'g');
insert into tb_1 values(2 , 'c');
insert into tb_1 values(3 ,'t');
insert into tb_1 values(4 ,'8');
insert into tb_1 values(0 ,'9');select * from tb_1 order by decode(a,1,1,2),a;
/*
A B
---------- ----------
1 a
1 g
0 9
2 c
3 t
4 8已选择6行。
*/
你的做法有问题,应该是这样的select * from tb_1 where a=1
UNION ALL
(SELECT * FROM (select * from tb_1 where a<>1 order by a))
/ A B
---------- ----------
1 a
1 g
0 9
2 c
3 t
4 86 rows selected