rocklee00
天涯行舟
采纳率100%
2016-01-20 04:43 阅读 1.6k

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

1

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 从今以后生命中的每一秒都属于我爱的人 2016-01-20 04: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
    
    点赞 1 评论 复制链接分享
  • rocklee00 天涯行舟 2016-01-20 05: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' 附近有语法错误。
    怎么改啊,谢谢

    点赞 评论 复制链接分享

相关推荐