先计算总条数,再乘以比例,得出条数,最后去limitselect round(count(1)*比例) as cnt from tb; select * from tb limit cnt;cnt要计算好替换到limit后面才可以。例如:select round(count(1)*0.1049) as cnt from tb; //假设结果190172 select * from tb limit 190172;不知是否有理解错再来个纯SQL版的,只要传入比例值即可select *,@i:=@i+1 as idx from tb,(select @i:=0)t where @i<(select round(count(1)*比例值) from tb);
先计算总条数,再乘以比例,得出条数,最后去limit
cnt要计算好替换到limit后面才可以。
例如:
不知是否有理解错
再来个纯SQL版的,只要传入比例值即可