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