如何在MySQL里构造SQL语句,自动给查询出来的结果加一列从1开始的序号列

两种办法:

第一种:快捷

select (@i:=@i+1) as i,a.* from zakk_carinfo_201811 a,(select @i:=0) as it
where CI_ThroughTime between "2018-11-28 00:00:00" and "2018-11-28 23:59:59";

zakk_carinfo_201811是表名,这样设计出来的语句查询速度不慢

第二种:啰嗦

set @rownum=0;

select @rownum:=@rownum+1 as rownum, a.* from zakk_carinfo_201811 a limit 1,1000;

猜你喜欢

转载自blog.csdn.net/Cinway/article/details/84583259