当前位置:网站首页>面试突击63:MySQL 中如何去重?
面试突击63:MySQL 中如何去重?
2022-07-06 09:39:00 【InfoQ】
1.创建测试数据
-- 创建测试表
drop table if exists pageview;
create table pageview(
id bigint primary key auto_increment comment '自增主键',
aid bigint not null comment '文章ID',
uid bigint not null comment '(访问)用户ID',
createtime datetime default now() comment '创建时间'
) default charset='utf8mb4';
-- 添加测试数据
insert into pageview(aid,uid) values(1,1);
insert into pageview(aid,uid) values(1,1);
insert into pageview(aid,uid) values(2,1);
insert into pageview(aid,uid) values(2,2);

2.distinct 使用
SELECT DISTINCT column_name,column_name FROM table_name;
2.1 单列去重

2.2 多列去重

2.3 聚合函数+去重

3.group by 使用
SELECT column_name,column_name FROM table_name
WHERE column_name operator value
GROUP BY column_name
3.1 单列去重

3.2 多列去重

3.3 聚合函数 + group by

4.distinct 和 group by 的区别

区别1:查询结果集不同



区别2:使用业务场景不同


区别3:性能不同
总结
参考 & 鸣谢
边栏推荐
- Application service configurator (regular, database backup, file backup, remote backup)
- Flexible report v1.0 (simple version)
- Junit单元测试
- Binary search strategy
- Establishment of graphical monitoring grafana
- 【MySQL入门】第三话 · MySQL中常见的数据类型
- The solution to the left-right sliding conflict caused by nesting Baidu MapView in the fragment of viewpager
- C#版Selenium操作Chrome全屏模式显示(F11)
- Flink analysis (I): basic concept analysis
- Precipitated database operation class - version C (SQL Server)
猜你喜欢
![[ASM] introduction and use of bytecode operation classwriter class](/img/0b/87c9851e577df8dcf8198a272b81bd.png)
[ASM] introduction and use of bytecode operation classwriter class

Vscode matches and replaces the brackets

虚拟机启动提示Probing EDD (edd=off to disable)错误

Integrated development management platform

Flink analysis (II): analysis of backpressure mechanism

EasyRE WriteUp

02个人研发的产品及推广-短信平台

List set data removal (list.sublist.clear)
![[elastic] elastic lacks xpack and cannot create template unknown setting index lifecycle. name index. lifecycle. rollover_ alias](/img/03/ece7f7b28cd9caea4240635548c77f.jpg)
[elastic] elastic lacks xpack and cannot create template unknown setting index lifecycle. name index. lifecycle. rollover_ alias

05个人研发的产品及推广-数据同步工具
随机推荐
Flink parsing (VII): time window
Application service configurator (regular, database backup, file backup, remote backup)
PySpark算子处理空间数据全解析(5): 如何在PySpark里面使用空间运算接口
Total / statistics function of MySQL
网络分层概念及基本知识
Xin'an Second Edition: Chapter 12 network security audit technology principle and application learning notes
The most complete tcpdump and Wireshark packet capturing practice in the whole network
Pyspark operator processing spatial data full parsing (5): how to use spatial operation interface in pyspark
Case: check the empty field [annotation + reflection + custom exception]
基于LNMP部署flask项目
Summary of study notes for 2022 soft exam information security engineer preparation
信息与网络安全期末复习(完整版)
EasyCVR接入设备开启音频后,视频无法正常播放是什么原因?
[translation] principle analysis of X Window Manager (I)
Display picture of DataGridView cell in C WinForm
04 products and promotion developed by individuals - data push tool
C # nanoframework lighting and key esp32
EasyCVR电子地图中设备播放器loading样式的居中对齐优化
Redis installation on centos7
PySpark算子处理空间数据全解析(4): 先说说空间运算