zoukankan      html  css  js  c++  java
  • 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;

    实现结果截图:

  • 相关阅读:
    动态数组arraylist的使用
    第一次
    layui.mobile.css
    index.html
    Ansible部署配置
    微服务项目配置文件
    镜像挂载
    网卡设置
    获取内存信息
    超时方法
  • 原文地址:https://www.cnblogs.com/zhming26/p/5923996.html
Copyright © 2011-2022 走看看