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;

    实现结果截图:

  • 相关阅读:
    nginx配置文件详解
    centos 小知识
    nginx 常见问题
    centos7.5 安装nginx
    tomact 配置远程登录
    Centos7 离线安装 mariaDB
    Crontab详细用法-定时任务详解
    新项目push/pull到github
    GIT的基本操作
    hive的安装
  • 原文地址:https://www.cnblogs.com/zhming26/p/5923996.html
Copyright © 2011-2022 走看看