当前位置:网站首页>Interview assault 63: how to remove duplication in MySQL?
Interview assault 63: how to remove duplication in MySQL?
2022-07-06 17:48:00 【InfoQ】
1. Create test data
-- Create test table
drop table if exists pageview;
create table pageview(
id bigint primary key auto_increment comment ' Since the primary key ',
aid bigint not null comment ' article ID',
uid bigint not null comment '( visit ) user ID',
createtime datetime default now() comment ' Creation time '
) default charset='utf8mb4';
-- Add test data
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 Use
SELECT DISTINCT column_name,column_name FROM table_name;
2.1 Separate the heavy ones

2.2 More than one, more than one

2.3 Aggregate functions + duplicate removal

3.group by Use
SELECT column_name,column_name FROM table_name
WHERE column_name operator value
GROUP BY column_name
3.1 Separate the heavy ones

3.2 More than one, more than one

3.3 Aggregate functions + group by

4.distinct and group by The difference between

difference 1: The query result set is different



difference 2: Different business scenarios


difference 3: Different performance
summary
Reference resources & Acknowledgement
边栏推荐
- C WinForm series button easy to use
- Compile and build, from the bottom to the top
- Solrcloud related commands
- EasyCVR授权到期页面无法登录,该如何解决?
- 自动化运维利器ansible基础
- 开源与安全的“冰与火之歌”
- Error: Publish of Process project to Orchestrator failed. The operation has timed out.
- JMeter interface test response data garbled
- The shell generates JSON arrays and inserts them into the database
- Kali2021 installation and basic configuration
猜你喜欢

Flink analysis (II): analysis of backpressure mechanism

Spark accumulator and broadcast variables and beginners of sparksql

pip install pyodbc : ERROR: Command errored out with exit status 1

Automatic operation and maintenance sharp weapon ansible Foundation

Zen integration nails, bugs, needs, etc. are reminded by nails

Huawei certified cloud computing hica

yarn : 无法加载文件 D:\ProgramFiles\nodejs\yarn.ps1,因为在此系统上禁止运行脚本

Flink parsing (III): memory management

Unity小技巧 - 绘制瞄准准心

Models used in data warehouse modeling and layered introduction
随机推荐
04 products and promotion developed by individuals - data push tool
Display picture of DataGridView cell in C WinForm
Vscode matches and replaces the brackets
PyTorch 提取中间层特征?
偷窃他人漏洞报告变卖成副业,漏洞赏金平台出“内鬼”
Unity粒子特效系列-闪星星的宝箱
Selenium test of automatic answer runs directly in the browser, just like real users.
connection reset by peer
Integrated development management platform
Openharmony developer documentation open source project
EasyCVR授权到期页面无法登录,该如何解决?
传统家装有落差,VR全景家装让你体验新房落成效果
Hongmeng introduction and development environment construction
Solrcloud related commands
2022年大厂Android面试题汇总(一)(含答案)
Deploy flask project based on LNMP
mysql高級(索引,視圖,存儲過程,函數,修改密碼)
The art of Engineering
The solution to the left-right sliding conflict caused by nesting Baidu MapView in the fragment of viewpager
How to output special symbols in shell