开心一笑: 会买水果的狗狗

    关注微信公众号

    QQ群:831045818

    app下载

    当前位置:首页> 数据库使用 > 技术文档 > 正文
    mysql去重 distinct多个字段
    发布时间:2022-09-15 13:41:28.0 浏览次数:
    select count(distinct(nameAndAge)) from (
    select concat(name,age) as nameAndAge FROM student_info
    ) newtable // 别名表很重要
    
    
    select distinct(nameAndAge),id,name,age from (
    select concat(name,age) as nameAndAge FROM student_info
    ) newtable // 别名表很重要
    
    //多个字段去重并显示多个字段 指定age排序
    select distinct(nameAndAge),id,name,age from (
        select id,name,age, concat(name,age) as nameAndAge FROM student_info  GROUP BY age desc
    ) newtable GROUP BY nameAndAge 
    
    
    //单个字段
    select distinct(name) FROM student_info
    
    //显示多个字段 必须加where条件
    select distinct(name),id,age FROM where age=14 student_info GROUP BY name
    
    
    //distinct 多字段处理效率慢,可以通过 group by功能去重
    
    //单个age去重
    select id,name,age FROM student_info  GROUP BY age desc
    
    //多个字段(不严谨)
    select id,name,age FROM student_info  GROUP BY name,age desc
    //严谨
    select id,name,age,concat(name,age) as nameAndAge FROM student_info  GROUP BY nameAndAge desc
    
    //排序,先去重 再排序
    select * from(
        select id,name,age,concat(name,age) as nameAndAge FROM student_info  GROUP BY nameAndAge desc
    )newtab  where 1=1 ...   GROUP BY age desc


    关注"都市百货" 了解南陵

    微信咨询wanglf2r(不拉群 发广告者勿加)

    0
    0
    上一篇:js 获取时间 上一篇:linux 计划任务

    评论已有0

    提交评论

    热门评论

    南陵新闻
    公示公告
    常用查询
    风光南陵
    走出南陵
    友情链接