当前位置:网站首页>面试突击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:性能不同
总结
参考 & 鸣谢
边栏推荐
- C # nanoframework lighting and key esp32
- C#WinForm中的dataGridView滚动条定位
- 【MySQL入门】第三话 · MySQL中常见的数据类型
- Single responsibility principle
- 自动答题 之 Selenium测试直接运行在浏览器中,就像真正的用户在操作一样。
- 华为认证云计算HICA
- MySQL Advanced (index, view, stored procedures, functions, Change password)
- MySQL basic addition, deletion, modification and query of SQL statements
- Chrome prompts the solution of "your company management" (the startup page is bound to the company's official website and cannot be modified)
- Xin'an Second Edition: Chapter 26 big data security demand analysis and security protection engineering learning notes
猜你喜欢

Spark calculation operator and some small details in liunx

当前系统缺少NTFS格式转换器(convert.exe)

C# WinForm中DataGridView单元格显示图片

轻量级计划服务工具研发与实践

Uipath browser performs actions in the new tab

Integrated development management platform

学 SQL 必须了解的 10 个高级概念

Vscode matches and replaces the brackets

Kali2021 installation and basic configuration

Pyspark operator processing spatial data full parsing (4): let's talk about spatial operations first
随机推荐
Selenium test of automatic answer runs directly in the browser, just like real users.
PySpark算子处理空间数据全解析(4): 先说说空间运算
C#WinForm中的dataGridView滚动条定位
[CISCN 2021 华南赛区]rsa Writeup
在一台服务器上部署多个EasyCVR出现报错“Press any to exit”,如何解决?
EasyRE WriteUp
Guidelines for preparing for the 2022 soft exam information security engineer exam
Wordcloud colormap color set and custom colors
Xin'an Second Edition: Chapter 12 network security audit technology principle and application learning notes
Application service configurator (regular, database backup, file backup, remote backup)
Xin'an Second Edition: Chapter 25 mobile application security requirements analysis and security protection engineering learning notes
Kernel link script parsing
Development and practice of lightweight planning service tools
C# NanoFramework 点灯和按键 之 ESP32
FlutterWeb浏览器刷新后无法回退的解决方案
OpenCV中如何使用滚动条动态调整参数
Remote code execution penetration test - B module test
[reverse intermediate] eager to try
[reverse primary] Unique
The most complete tcpdump and Wireshark packet capturing practice in the whole network