数据库中通过group by找出表中的重复数据

  有时候在做数据割接时会碰到数据插入失败的情况,大部分都是导出的数据中存在重复导致的。我们可以通过查询语句带分组条件来确认是否有重复数据。例如我现在有表 t_wlf_info,其中有个 username字段,我可以通过如下语句看username的重复记录:

select * from t_wlf_info where username in (select username from t_wlf_info group by username having count(*) > 1);

  也可以通过这条语句只看有多少条重复记录:

select * from (select username, count(*) count from t_wlf_info group by username) t where t.count > 1;

  有时候在做数据割接时会碰到数据插入失败的情况,大部分都是导出的数据中存在重复导致的。我们可以通过查询语句带分组条件来确认是否有重复数据。例如我现在有表 t_wlf_info,其中有个 username字段,我可以通过如下语句看username的重复记录:

select * from t_wlf_info where username in (select username from t_wlf_info group by username having count(*) > 1);

  也可以通过这条语句只看有多少条重复记录:

select * from (select username, count(*) count from t_wlf_info group by username) t where t.count > 1;

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-02-18
  • 2022-12-23
  • 2022-12-23
  • 2022-02-26
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-28
  • 2022-12-23
  • 2021-11-23
  • 2021-11-05
  • 2022-01-17
  • 2021-12-04
  • 2022-01-29
相关资源
相似解决方案