mysql中根據一個字段相同記錄寫遞增序號,如序號結果,如何實現?


 

mysql中根據一個字段相同記錄寫遞增序號,如序號結果,如何實現?

mysql中實現方式如下:

select 
    merchantId,
    NameCn,
    send_date,
    deliver_name,
    deliver_address,
    contact,
    bill_status,
    bill_code,
    rank
from
    (select 
        heyf_tmp.merchantId,
        heyf_tmp.NameCn,
            heyf_tmp.send_date,
            heyf_tmp.deliver_name,
            heyf_tmp.deliver_address,
            heyf_tmp.contact,
            heyf_tmp.bill_status,
            heyf_tmp.bill_code,
            @rownum:=@rownum + 1,
            if(@pdept = heyf_tmp.contact, @rank:=@rank + 1, @rank:=1) as rank,
            @pdept:=heyf_tmp.contact
    from
        (select 
    t1.merchantId,
    t2.NameCn,
    t1.send_date,
    t1.deliver_name,
    t1.deliver_address,
    concat(t1.deliver_phone,',',t1.deliver_mobile) as 'contact',
    t1.bill_status,
    t1.bill_code
from
    bill_master t1
left join 
    sys_merchant_master t2 on t1.merchantId = t2.merchantId
where
    bill_status != 10
order by deliver_phone,deliver_mobile) heyf_tmp, (select @rownum:=0, @pdept:=null, @rank:=0) a) result;

實現結果截圖:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM