当前位置:网站首页>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
边栏推荐
- How to carry out modular power operation efficiently
- ERP的权限管理的操作与设计--开源软件诞生24
- 剑指offer之打印超过数组一半的数字
- PHP - cURL复制粘贴性接入短信验证码示例
- A practical chrome Gadget: xtrace
- How to use binary search algorithm
- 财务管理系统如何帮助企业实现财务自动化管理?
- Performance evaluation report of YoMo codec - Y3
- Realization of commodity backstage system
- Android instance - simple login layout
猜你喜欢
[graffiti Internet of things footprint] graffiti cloud platform interface description
Almost finished all the list titles, I found these things...
How to implement LRU algorithm
How to page query after the 10 billion level data sub table?
AQS source code in-depth analysis of conditional queue
当我们开发一个接口时需要注意些什么
传统采购模式已变!汽车采购职能该如何创新?
如何k个一组反转链表
Hand in hand to teach you to use container service tke cluster audit troubleshooting
How to greatly improve the performance of larravel framework under php7? Install stone!
随机推荐
[最佳实践]了解 Eolinker 如何助力远程办公
lvgl 库 V7版本相关应用
Double 11 big second kill, cloud server as low as 0.7 fold
From master of Engineering Physics of Tsinghua University to open source entrepreneur of cloud computing
说说 C# 9 新特性的实际运用
Git老鸟查询手册
容器技术(三)搭建本地 Registry【15】
Container technology (3) mirror summary [16]
Container technology (3) building local registry [15]
day84:luffy:优惠活动策略&用户认证&购物车商品的勾选/结算
win7+vs2015+cuda10.2配置TensorRT7.0
mongodb 源码实现系列 - 网络传输层模块实现三
How to make a set of K reverse linked lists
刚毕业都会迷茫,我经过7年总结,送给程序员的你们7点建议
Super low price cloud server is coming
如何用代码上传头像,并添加自己的版权信息?
How to use binary search algorithm
骚操作!嵌套 JSON 秒变 Dataframe!
expect ':' at 0, actual = (JSON转化异常解决)
[stm32h7] Chapter 6: stm32h7 dma2d acceleration of ThreadX guix