(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
鏈接:http://www.qianxingweb.com