zoukankan      html  css  js  c++  java
  • 数据库重复记录筛选

    查询f_name 重复的记录
    select * from t_info a where ((select count(*) from t_info where f_name = a.f_name) > 1) order by f_name desc

    select * from t_info where f_name in (select f_name from t_info group by f_name having count(*)>1)

    查询f_name 重复的记录条数
    select f_name, count(*) as number from t_info a where ((select count(*) from t_info where f_name = a.f_name) > 1) group by f_name

    select f_name, count(*) as number from t_info where f_name in (select f_name from t_info group by f_name having count(*)>1) group by f_name

    过滤重复记录(只显示一条,注:此处显示f_id最大一条记录)
    select * from t_info where f_id in (select max(f_id) from t_info group by f_name)

    删除全部重复记录(慎用)
    delete t_info where f_name in (select f_name from t_info group by f_name having count(*)>1)
    保留一条 (注:此处保留id最大一条记录)
    delete t_info where f_id not in (select max(f_id) from t_info group by f_name)
    在mysql中要用not in 删除需要按照下面的执行,不知为啥
    delete t_info where f_id not in (select * from (select max(f_id) from t_info group by f_name))

  • 相关阅读:
    机器学习八
    机器学习七
    机器学习六
    机器学习五
    JMeter获取复杂的JSON串中的参数的值
    Jmeter返回参数值写入文件
    python 连接数据库
    jmeter返回的Unicode转换成utf8
    Appium与python自动测试环境及demo详解
    python解析复杂json字符串
  • 原文地址:https://www.cnblogs.com/robertsun/p/4263368.html
Copyright © 2011-2022 走看看