select (@i:=@i+1) as i,table_name.* from table_name,(select @i:=0) as it
第二种方法:
set @rownum=0
select @rownum:=@rownum+1 as rownum, t.username from auth_user t limit 1,5
现在要按年龄从大到小取出前5条数据的话,可用如下语句:1
2
3
4
select 姓名,年龄
from
(select 姓名,年龄,row_number() over (order by 年龄 desc) as rn from student) t
where rn<=5
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)