以下查询将导致100行:
$qtop = Quest::where('ttype',$id)
->where('country', $ucountry )
->where('score', '>' , 240 )
->orderby('score', 'desc')
// ->take(25)
->get();
而不是使用->take(25)
25%的总行数呢?
在纯SQL Server语法中,您可以使用TOP 25 PERCENT
select TOP 25 PERCENT * from table
对于普通的mysql,您需要使用嵌套查询@see将SQL Server查询转换为MySQL:
SELECT *
FROM
(
SELECT table.*, @counter := @counter +1 counter
FROM (select @counter:=0) initvar, table
ORDER BY score
) X
WHERE X.counter <= (25/100 * @counter)
ORDER BY score
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句