Mysql taken before each packet odd N data

1. Obtain data specified sort:

select * from table order by type

 2. The results obtained to increase the statistical field:

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

 3. The combination statement:

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

  



4. query gets results:
select * from ( ... ) where total<=N

 

Guess you like

Origin www.cnblogs.com/itwlp/p/11597112.html