只能再查詢自增ID即可
創(chuàng)新互聯(lián)擁有一支富有激情的企業(yè)網(wǎng)站制作團(tuán)隊(duì),在互聯(lián)網(wǎng)網(wǎng)站建設(shè)行業(yè)深耕十多年,專業(yè)且經(jīng)驗(yàn)豐富。十多年網(wǎng)站優(yōu)化營(yíng)銷經(jīng)驗(yàn),我們已為上1000+中小企業(yè)提供了成都做網(wǎng)站、網(wǎng)站建設(shè)解決方案,定制網(wǎng)站制作,設(shè)計(jì)滿意,售后服務(wù)無憂。所有客戶皆提供一年免費(fèi)網(wǎng)站維護(hù)!
具體操作:MYSQL獲取自增ID的四種方法
select max(id) from tablename
SELECT LAST_INSERT_ID() 函數(shù)
LAST_INSERT_ID 是與table無關(guān)的,如果向表a插入數(shù)據(jù)后,再向表b插入數(shù)據(jù),LAST_INSERT_ID會(huì)改變。
求出一周數(shù)據(jù)排行榜
select *from DOWNLOADRECORDS where DOWNLOADRECORDS_TIMEDATE_SUB(now(),INTERVAL 7 DAY);
求出24小時(shí)內(nèi)數(shù)據(jù)排行榜
select *from DOWNLOADRECORDS where DOWNLOADRECORDS_TIMEDATE_SUB(now(),INTERVAL 1 DAY)
求出一月內(nèi)數(shù)據(jù)排行榜
select *from DOWNLOADRECORDS where DOWNLOADRECORDS_TIMEDATE_SUB(now(),INTERVAL 1 MONTH)
為日期增加一個(gè)時(shí)間間隔:date_add()
修改sql如下
select (@xh := @xh + 1) as xh, a.* from (select * from auto where level = 3) a, (select @xh := 0) x;
結(jié)果如下
我假設(shè)你原來查出N條數(shù)據(jù)的代碼如下:(你自己替換成你的)
select * from tb order by col ;
現(xiàn)在你改成這樣:
SET @row_number =0;
select *, @row_number := @row_number+1 AS row_number
from tb
order by col;
--看到了吧 用變量來產(chǎn)生一個(gè)序列
--如果你要查詢特定值,可以這樣
select row_number
from (
select *, @row_number := @row_number+1 AS row_number
from tb
order by col) k
where 字段名='你要的字段值';