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;

实现结果截图:

 

posted @ 2016-09-30 15:48  zhming  阅读(8281)  评论(1编辑  收藏  举报