当前位置:网站首页>面试突击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:性能不同
总结
参考 & 鸣谢
边栏推荐
- TCP connection is more than communicating with TCP protocol
- Basic configuration and use of spark
- [VNCTF 2022]ezmath wp
- 05 personal R & D products and promotion - data synchronization tool
- EasyCVR接入设备开启音频后,视频无法正常播放是什么原因?
- MySQL basic addition, deletion, modification and query of SQL statements
- Display picture of DataGridView cell in C WinForm
- Akamai anti confusion
- 远程代码执行渗透测试——B模块测试
- 应用服务配置器(定时,数据库备份,文件备份,异地备份)
猜你喜欢
EasyCVR电子地图中设备播放器loading样式的居中对齐优化
[elastic] elastic lacks xpack and cannot create template unknown setting index lifecycle. name index. lifecycle. rollover_ alias
C# WinForm系列-Button简单使用
02个人研发的产品及推广-短信平台
Re signal writeup
2022年大厂Android面试题汇总(一)(含答案)
PySpark算子处理空间数据全解析(4): 先说说空间运算
[reverse primary] Unique
[reverse] repair IAT and close ASLR after shelling
EasyCVR接入设备开启音频后,视频无法正常播放是什么原因?
随机推荐
华为认证云计算HICA
Models used in data warehouse modeling and layered introduction
Interpretation of Flink source code (II): Interpretation of jobgraph source code
沉淀下来的数据库操作类-C#版(SQL Server)
2021-03-22 "display login screen during recovery" can't be canceled. The appearance of lock screen interface leads to the solution that the remotely connected virtual machine can't work normally
[getting started with MySQL] fourth, explore operators in MySQL with Kiko
集成开发管理平台
05个人研发的产品及推广-数据同步工具
Akamai anti confusion
DataGridView scroll bar positioning in C WinForm
Integrated development management platform
Connect to LAN MySQL
EasyRE WriteUp
Vscode matches and replaces the brackets
轻量级计划服务工具研发与实践
Based on infragistics Document. Excel export table class
07 personal R & D products and promotion - human resources information management system
Quick start of Hongmeng system
The most complete tcpdump and Wireshark packet capturing practice in the whole network
Flink parsing (V): state and state backend