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))

  • 相关阅读:
    java中排序算法
    maven常用命令
    Team_GJX模板整理
    BZOJ 4128
    BZOJ 1169: [Baltic2008]Grid
    Codeforces Round #448 (Div. 2)
    HDU 5942
    2016 ICPC 沈阳
    2016 ICPC 北京
    2016 CCPC 杭州
  • 原文地址:https://www.cnblogs.com/robertsun/p/4263368.html
Copyright © 2011-2022 走看看