2 rocklee00 rocklee00 于 2016.01.20 12:43 提问

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个回答

caozhy
caozhy   Ds   Rxr 2016.01.20 12:52
已采纳
 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
rocklee00 排序以b,c解决了
接近 2 年之前 回复
rocklee00
rocklee00 排序以b,c解决了
接近 2 年之前 回复
rocklee00
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
接近 2 年之前 回复
rocklee00
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' 附近有语法错误。 怎么改啊,谢谢
接近 2 年之前 回复
rocklee00
rocklee00   2016.01.20 13:18

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
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!