Mysql中查询与删除重复行的一些复杂的sql语句
技术百科
黄舟
发布时间:2017-05-21
浏览: 次 这篇文章主要介绍了mysql一些复杂的sql语句
(查询与删除重复的行),需要的朋友可以参考下
1.查找重复的行
SELECT * FROM blog_user_relation a WHERE (a.account_instance_id,a.follow_account_instance_id) IN (SELECT account_instance_id,follow_account_instance_id FROM blog_user_relation GROUP BY account_instance_id, follow_account_instance_id HAVING COUNT(*) > 1)
2.删除重复的行(保留一条)
PS:因为mysql的delete,如果被删的表的where条件里有in,且in里面也有此表,那就删除不了。
/*创建个临时表*/ CREATE TABLE blog_user_relation_temp AS ( SELECT * FROM blog_user_relation a WHERE (a.account_instance_id,a.follow_account_instance_id) IN ( SELECT account_instance_id,follow_account_instance_id FROM blog_user_relation GROUP BY account_instance_id, follow_account_instance_id HAVING COUNT(*) > 1) AND relation_id NOT IN (SELECT MIN(relation_id) FROM blog_user_relation GROUP BY account_instance_id, follow_account_instance_id HAVING COUNT(*)>1)); /*删除数据*/ DELETE FROM `blog_user_relation` WHERE relation_id IN (SELECT relation_id FROM blog_user_relation_temp); /*删除临时表*/ DROP TABLE blog_user_relation_temp;
# 那就
# 也有
# 这篇文章
# cn
# hongkong
# keji
# jpg
# aliyucs
# mysql
# sql
# pre
相关栏目:
<?muma
$count = M('archives')->where(['typeid'=>$field['id']])->count();
?>
【
AI推广<?muma echo $count; ?>
】
<?muma
$count = M('archives')->where(['typeid'=>$field['id']])->count();
?>
【
SEO优化<?muma echo $count; ?>
】
<?muma
$count = M('archives')->where(['typeid'=>$field['id']])->count();
?>
【
技术百科<?muma echo $count; ?>
】
<?muma
$count = M('archives')->where(['typeid'=>$field['id']])->count();
?>
【
谷歌推广<?muma echo $count; ?>
】
<?muma
$count = M('archives')->where(['typeid'=>$field['id']])->count();
?>
【
百度推广<?muma echo $count; ?>
】
<?muma
$count = M('archives')->where(['typeid'=>$field['id']])->count();
?>
【
网络营销<?muma echo $count; ?>
】
<?muma
$count = M('archives')->where(['typeid'=>$field['id']])->count();
?>
【
案例网站<?muma echo $count; ?>
】
<?muma
$count = M('archives')->where(['typeid'=>$field['id']])->count();
?>
【
精选文章<?muma echo $count; ?>
】
相关推荐
- Linux如何安装JDK11_Linux环境变量配
- Windows10如何彻底关闭自动更新_Win10
- php在Linux怎么部署_LNMP环境搭建PHP
- windows 10专注助手怎么关闭_window
- Win11开机自检怎么关闭_跳过Win11开机磁盘
- 如何用列表一次性对 DataFrame 的指定列应
- windows系统如何安装cab更新补丁_wind
- windows系统找不到无线网络怎么办_windo
- Win11怎么关闭透明效果_Windows11辅助
- GML (Geography Markup Lan
- 如何使用Golang实现微服务状态监控_Golan
- php订单日志怎么记录发货_php记录订单发货操作
- Win11怎么恢复旧版开始菜单_通过软件还原Win
- 如何用正则与预处理高效拦截带干扰符的恶意域名
- Win11怎么恢复误删照片_Win11数据恢复工具
- c++怎么使用std::unique实现去重_c+
- Win10系统怎么查看显卡温度_Win10任务管理
- Win11怎么关闭资讯和兴趣_Windows11任
- 如何使用Golang构建基础消息队列模拟_Gola
- Python网络日志追踪_请求定位解析【教程】
- Python深度学习实战教程_神经网络模型构建与训
- Windows10如何更改日期格式_Win10区域
- 如何在Golang中引入测试模块_Golang测试
- php8.4匿名类怎么用_php8.4匿名类创建与
- Python字符串操作教程_切片拼接与格式化详解
- Go 中 defer 语句在 goroutine
- Linux怎么设置磁盘配额_Linux系统Quot
- 如何在Golang中指定模块版本_使用go.mod
- Win11视频默认播放器怎么改_Win11关联第三
- 如何关闭Win10自动更新更新_Win10系统自动
- 如何在 Go 中正确反序列化多个同级 XML 元素
- Win11怎么设置单手模式_Win11触控键盘布局
- Python列表推导式与字典推导式教程_简化代码高
- Python迭代器生成器进阶教程_节省内存与懒加载
- 如何使用Golang管理模块版本_Golanggo
- Win10怎样设置多显示器_Win10多显示器扩展
- Windows10系统怎么查看硬盘健康_Win10
- php做exe支持多线程吗_并发处理实现方式【详解
- Win10怎样安装PPT模板_Win10安装PPT
- Python网页解析流程_html结构说明【指导】
- C++中的std::shared_from_thi
- Windows10系统怎么查看显卡驱动_Win10
- Win11怎么退出高对比度模式_Win11取消反色
- Win11怎么更改系统语言_Win11中文语言包下
- Win11怎么开启专注模式_Windows11时钟
- Win11怎么退出微软账户_切换Win11为本地账
- 一文教你快速开通网站LOGO图
- Win11笔记本怎么看电池健康度_Win11电池报
- Linux如何使用Curl发送请求_Linux下A
- Python函数参数高级用法_默认值与可变参数解析

QQ客服