当前位置:网站首页>sql 筛选查询重复列
sql 筛选查询重复列
2020-11-09 22:26:00 【龘游戏人生龘】
id_cardxx 为 table;id,id_card,phone均为字段
-- 显示重复列 select * from 表名 where 列名 in (select 列名 from 表名 group by 列名 having COUNT(*)>1) order by 列名
select * from file_selection where mash in (select mash from file_selection group by mash having COUNT(*)>1) order by mash
-- 查询重复数据但排除 最小id MIN( id )
SELECT *
FROM
id_cardxx c
WHERE
EXISTS (
SELECT
a.id
FROM
id_cardxx a,
( SELECT id_card, MIN( id ) AS rid FROM id_cardxx GROUP BY id_card HAVING count( 1 ) > 1 ) b
WHERE
a.id_card = b.id_card
AND a.id != b.rid
AND c.id = a.id
)
AND id > 8071
AND phone IS NULL
ORDER BY
c.id_card;
-- 修改则需要将查询出来的数据当作新表在查询一次 及
UPDATE id_cardxx
set 修改字段 = 'xxxx'
WHERE id in ( SELECT....end ) as xx1
-- 完整sql
UPDATE id_cardxx
set source = 'xxxx'
WHERE id in (
SELECT xx1.id FROM
(
SELECT id
FROM
id_cardxx c
WHERE
EXISTS (
SELECT
a.id
FROM
id_cardxx a,
( SELECT id_card, MIN( id ) AS rid FROM id_cardxx GROUP BY id_card HAVING count( 1 ) > 1 ) b
WHERE
a.id_card = b.id_card
AND a.id != b.rid
AND c.id = a.id
)
AND id > 8071
AND phone IS NULL
) as xx1
)
版权声明
本文为[龘游戏人生龘]所创,转载请带上原文链接,感谢
https://my.oschina.net/u/3628379/blog/4710169
边栏推荐
- Nine kinds of distributed primary key ID generation schemes of sub database and sub table are quite comprehensive
- 正式班D25
- Git老鸟查询手册
- 如何k个一组反转链表
- input 与 button 的问题 (空隙/不等高/对不齐)及 解决办法
- 磁阻式随机存储器MRAM基本原理
- How to carry out modular power operation efficiently
- What if the Mac can't connect to the app store and prompts you to connect to the network?
- Open source project, private tool, rapid development
- 如何用代码上传头像,并添加自己的版权信息?
猜你喜欢

刚毕业都会迷茫,我经过7年总结,送给程序员的你们7点建议

配置ng-zerro的nz-date-picker时间选择组件

How to gracefully prevent switch switching of view UI?

How to page query after the 10 billion level data sub table?

Hand in hand to teach you to use container service tke cluster audit troubleshooting

60 余位技术高管齐聚松山湖,华为云第一期核心伙伴开发者训练营圆满落幕

在PHP7下怎么大幅度提升Laravel框架性能?安装Stone!

Postman(一)---功能介绍

40 tips for life that may be useful

如何实现LRU算法
随机推荐
如何运用二分查找算法
Git old bird search manual
【QT】子类化QObject+moveToThread实现多线程
京淘项目day10
Hand in hand to teach you to use container service tke cluster audit troubleshooting
[best practice] learn how eolinker helps Telecommuting
Operation! Nested JSON second change dataframe!
SQL server attached database access denial resolution summary
毕业设计之 ---基于微服务框架的电影院订票系统
传统采购模式已变!汽车采购职能该如何创新?
容器技术(三)镜像小结【16】
说说 C# 9 新特性的实际运用
A great guide to curl
11.9
如何用代码上传头像,并添加自己的版权信息?
财务管理系统如何帮助企业实现财务自动化管理?
What if the Mac can't connect to the app store and prompts you to connect to the network?
Nine kinds of distributed primary key ID generation schemes of sub database and sub table are quite comprehensive
LeetCode 48 旋转图像
Kubernetes-18: installation and use of dashboard