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
4.查询获取结果:
select * from ( ... ) where total<=N