mysql查询前百分之几的数据(以25%为例)
因为mysql没有top的用法,而且limit后也不支持子查询所以实现相对麻烦,可以使用类似于Oracle中伪列的用法select @rownum:=@rownum+1,student.*from (select @rownum:=0) row ,student;可以看到表中有5条数数据select round(count(*)/4) from studentselect @...
·
因为mysql没有top的用法,而且limit后也不支持子查询所以实现相对麻烦,
可以使用类似于Oracle中伪列的用法
select @rownum:=@rownum+1,student.*
from (select @rownum:=0) row ,student;
可以看到表中有5条数数据
select round(count(*)/4) from student
补充一下这里的rownum只是个变量名,也可以是用其他的,不一定非得@rownum
select @rownum:=@rownum+1,student.*
from (select @rownum:=0) row ,student
where @rownum<(select round(count(*)/4) from student);//查询列号小于25%的数据
mysql不支持top和rowid感觉挺伤的
更多推荐
已为社区贡献1条内容
所有评论(0)