当前位置:网站首页>面试突击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:性能不同
总结
参考 & 鸣谢
边栏推荐
- The art of Engineering (2): the transformation from general type to specific type needs to be tested for legitimacy
- mysql高级(索引,视图,存储过程,函数,修改密码)
- Yarn: unable to load file d:\programfiles\nodejs\yarn PS1, because running scripts is prohibited on this system
- 自动化运维利器-Ansible-Playbook
- yarn : 无法加载文件 D:\ProgramFiles\nodejs\yarn.ps1,因为在此系统上禁止运行脚本
- Xin'an Second Edition: Chapter 23 cloud computing security requirements analysis and security protection engineering learning notes
- Vscode matches and replaces the brackets
- 2022年大厂Android面试题汇总(一)(含答案)
- 05个人研发的产品及推广-数据同步工具
- How does wechat prevent withdrawal come true?
猜你喜欢
Junit单元测试
C # nanoframework lighting and key esp32
TCP connection is more than communicating with TCP protocol
[reverse] repair IAT and close ASLR after shelling
[introduction to MySQL] third, common data types in MySQL
应用服务配置器(定时,数据库备份,文件备份,异地备份)
Spark calculation operator and some small details in liunx
Wordcloud colormap color set and custom colors
yarn : 无法加载文件 D:\ProgramFiles\nodejs\yarn.ps1,因为在此系统上禁止运行脚本
03 products and promotion developed by individuals - plan service configurator v3.0
随机推荐
Unity粒子特效系列-闪星星的宝箱
PyTorch 提取中间层特征?
Application service configurator (regular, database backup, file backup, remote backup)
信息与网络安全期末复习(完整版)
[ciscn 2021 South China]rsa writeup
Pyspark operator processing spatial data full parsing (4): let's talk about spatial operations first
Debug xv6
Models used in data warehouse modeling and layered introduction
FlutterWeb浏览器刷新后无法回退的解决方案
Detailed explanation of data types of MySQL columns
JUnit unit test
02 personal developed products and promotion - SMS platform
How uipath determines that an object is null
Redis installation on centos7
Interpretation of Flink source code (II): Interpretation of jobgraph source code
Kernel link script parsing
当前系统缺少NTFS格式转换器(convert.exe)
遠程代碼執行滲透測試——B模塊測試
04 products and promotion developed by individuals - data push tool
06个人研发的产品及推广-代码统计工具