• 无分组

    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 )

葬天尘
354 声望7 粉丝