问题描述
- 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
求高手指教?
解决方案
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
解决方案二:
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' 附近有语法错误。
怎么改啊,谢谢