SELECT t.*FROM (SELECT @rownum := 0) rJOIN table tWHERE (@rownum :=@rownum + 1) <= ( SELECT round(count(*) * 0.2)
-- 0.2查的就是20% FROM table ); table 就是实际的表名称
++++++++++++++++++++++++++++++++++++++++++++++++++++++
分两条
SELECT ceil(count(1)*0.2) as t from fn_open
SELECT * from fn_open limit t
++++++++++++++++++++++++++++++++++++++++++++++++++++++
limit count(id)* 0.2 |
---|