首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

问一条oracle的sql话语啊关于两个结果合并的

2013-04-02 
问一条oracle的sql语句啊,关于两个结果合并的。一个人员表:id,name,type。其中type表示分类用的,比如有1,2,3

问一条oracle的sql语句啊,关于两个结果合并的。
一个人员表:
id,name,type。其中type表示分类用的,比如有1,2,3的。
现在想查:
type=1的人放在前面,剩下的放在后面。
比如:
id1 王五 1
id2 张三 1
id3 李四 3
id4 赵六 1
id5 王麻子 2
查询的结果要
id1 王五 1
id2 张三 1
id4 赵六 1
id5 王麻子 2
id3 李四 3
至于不是1的排序随便。 sql语句
[解决办法]
group by 
[解决办法]
select * from tb order by decode(type,1), type; 
[解决办法]
用union all
先查询满足条件的,比如
select ...
where type = 1
union all
select ...
where type <> 1
[解决办法]

引用:
用union all
先查询满足条件的,比如
select ...
where type = 1
union all
select ...
where type <> 1

正解
[解决办法]
引用:
sorry,
it should be like this:
type=1:select * from tb order by decode(type,1,1,2), type; 
type=2:select * from tb order by decode(type,2,1,2), type; 

用decode确实不错
select * from tb order by decode(type,1,1),type
[解决办法]
引用:
引用:sorry,
it should be like this:
type=1:select * from tb order by decode(type,1,1,2), type; 
type=2:select * from tb order by decode(type,2,1,2), type; 
用decode确实不……
 id不需要排序吗?
[解决办法]
select id,name,type from [tablename] where type=1 union
select id,name,type from [tablename] where type<>1

热点排行