SQL数据记录如何错位组合排序输出?

SQL数据记录如何错位组合排序输出?
select a1,b1 from t 结果SQL记录如下:

10001,1000000001
10001,1000000002
10001,1000000003
10001,1000000004
10001,1000000005
10002,1000000006
10002,1000000007
10002,1000000008
10002,1000000009
10002,1000000010
10003,1000000011
10003,1000000012
10003,1000000013
10003,1000000014
10003,1000000015
如何排列成:
10001
1000000001
1000000002
1000000003
1000000004
1000000005
10002
1000000006
1000000007
1000000008
1000000009
1000000010
10003
1000000011
1000000012
1000000013
1000000014
1000000015
求高手指教?

2个回答

 select a from ((select distinct 第一列 as a, 第一列 as b, 0 as c from table)
union
(select distinct 第二列 as a, 第一列 as b, 1 as c from table))
orderby b
orderby a
orderby c
rocklee00
天涯行舟 排序以b,c解决了
4 年多之前 回复
rocklee00
天涯行舟 排序以b,c解决了
4 年多之前 回复
rocklee00
天涯行舟 select a from ( (select distinct a1 as a, a1 as b, 0 as c from t ) union (select distinct b1 as a, a1 as b, 1 as c from t) ) as tt order by b,c
4 年多之前 回复
rocklee00
天涯行舟 table t 字段 a1 , b2 执行sql select a from ( (select distinct a1 as a, a1 as b, 0 as c from t) union (select distinct b1 as a, a1 as b, 1 as c from t) ) order by b order by a order by c 提示关键字 'order' 附近有语法错误。 怎么改啊,谢谢
4 年多之前 回复

table t
a1 , b2
10001 1000000001
10001 1000000002
10001 1000000003
10001 1000000004
10001 1000000005
10002 1000000006
10002 1000000007
10002 1000000008
10002 1000000009
10002 1000000010
10003 1000000011
10003 1000000012
10003 1000000013
10003 1000000014
10003 1000000015
10004 1000000016
10004 1000000017
10004 1000000018
10004 1000000019
10004 1000000020
10005 1000000021
10005 1000000022
10005 1000000023
10005 1000000024
10005 1000000025
10006 1000000026
10006 1000000027
10006 1000000028
10006 1000000029
10006 1000000030

执行sql
select a from
(

(select distinct a1 as a, a1 as b, 0 as c from t)

union

(select distinct b1 as a, a1 as b, 1 as c from t)
)
order by b
order by a
order by c
提示关键字 'order' 附近有语法错误。
怎么改啊,谢谢

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐