Mysql auto-increment variable/increment sequence/increment sequence number and

 

(1) Method 1:

select   (@i:=@i+1)   as   i,table_name.*   from   table_name,(select   @i:=0)   as   it;

 

(2) Method 2:

set @rownum=0;

select @rownum:=@rownum+1 as rownum, t.username from auth_user t limit 1,5;

 

Example 1:

 drop table if exists yida_org.temp_tsxg_gt_01;

 create table yida_org.temp_tsxg_gt_01 as 

 select  (@i:=@i+1) as po_no ,a.*

 from (select * from temp_hui_yuan_GT01 order by ITEM_PRICE desc ) a ,(select   @i:=0)   as   it

;

 

Example 2:

select shipment_date ,sku ,quantity ,total ,(@i :=@i + 1) AS No

from test.temp_01 a ,(select @i:=0) as it

;

 

Guess you like

Origin blog.csdn.net/helunqu2017/article/details/113816019