如下:
--创建测试表 create table temp(id int(4),name varchar(20)); --写入数据 insert into temp values (1,"aaa"); insert into temp values (2,"bbb"); insert into temp values (3,"cccc"); insert into temp values (4,"ddd"); insert into temp values (5,"eee"); insert into temp values (6,"fff"); insert into temp values (7,"ggg"); insert into temp values (8,"hhh"); insert into temp values (9,"iii"); insert into temp values (10,"jjjj"); --实现获取行号 select @rownum:=@rownum+1 as rownum,name from temp,(select @rownum:=0) temp where @rownum<4
OK!
Tag: Mysql Mysql基础