(1)第一次执行时分组行号不起作用

  1.按指定排序获取数据:

select * from table order by type

  2.给获取的结果增加统计字段:

@num:=IF(@groups=`type`,@num+1,IF(@groups:=`type`,1,1)) as total 

  3.组合语句:

SELECT wid,name,type,@num:=IF(@groups=`type`,@num+1,IF(@groups:=`type`,1,1)) as total FROM w_websites ORDER BY type 

 

(2)分组加行号

SELECT a.type,IF(@v<>a.type,@r:=1,@r:=@r+1) as total,IF(@v<>a.type,@v:=a.type,@v) as ctype
FROM (SELECT @r:=0,@v:=-1) as c,w_websites a 
INNER JOIN xxx b
ON xxx
WHERE xxx
ORDER BY xxx

  Mysql的给分组加行号

链接:http://www.qianxingweb.com 

相关文章:

  • 2021-05-22
  • 2022-12-23
  • 2022-12-23
  • 2021-06-27
  • 2022-12-23
  • 2021-06-25
  • 2021-09-14
猜你喜欢
  • 2022-12-23
  • 2021-10-14
  • 2022-02-11
  • 2022-12-23
  • 2021-10-29
  • 2021-12-31
相关资源
相似解决方案