登录
首页 >  数据库 >  MySQL

MySQL 给数据排序同时追加序号列

来源:SegmentFault

时间:2023-01-20 14:59:54 438浏览 收藏

大家好,今天本人给大家带来文章《MySQL 给数据排序同时追加序号列》,文中内容主要涉及到MySQL、排序,如果你对数据库方面的知识点感兴趣,那就请各位朋友继续看下去吧~希望能真正帮到你们,谢谢!

  • 无分组

    select @rownum:=@rownum+1 as autoSeq,
    sid,pid,oprimary,seq
    from singlechoice,(select @rownum:=0) r
    order by pid,sid
  • 单字段分组

    select (@i := case  when  @tableName=a.tablename then @i + 1 else 1 end )  as rowIndex,
    a.*,(@tableName:=a.tablename)
    from tablestyle a,(select @i:=0,@tableName:='') as t
    group by tablename,fieldname
    order by tablename,(@i := case  when  @tableName=a.tablename then @i + 1 else 1 end )
  • 多字段分组

    select (@i := case  when  @tableName=concat(a.dbname,a.tablename) then @i + 1 else 1 end )  as rowIndex,
    a.*,(@tableName:=concat(a.dbname,a.tablename)) as temp
    from tablestyle a,(select @i:=0,@tableName:='') as t
    group by dbname,tablename,fieldname
    order by dbname,tablename,(@i := case  when  @tableName=concat(a.dbname,a.tablename) then @i + 1 else 1 end )

以上就是《MySQL 给数据排序同时追加序号列》的详细内容,更多关于mysql的资料请关注golang学习网公众号!

声明:本文转载于:SegmentFault 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>
评论列表