当前位置:网站首页>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
边栏推荐
- PySpark算子处理空间数据全解析(5): 如何在PySpark里面使用空间运算接口
- Kernel link script parsing
- Xin'an Second Edition; Chapter 11 learning notes on the principle and application of network physical isolation technology
- Unity particle special effects series - treasure chest of shining stars
- connection reset by peer
- DataGridView scroll bar positioning in C WinForm
- 重磅!蚂蚁开源可信隐私计算框架“隐语”,主流技术灵活组装、开发者友好分层设计...
- Optimization of middle alignment of loading style of device player in easycvr electronic map
- EasyCVR授权到期页面无法登录,该如何解决?
- 10 advanced concepts that must be understood in learning SQL
猜你喜欢
【Elastic】Elastic缺少xpack无法创建模板 unknown setting index.lifecycle.name index.lifecycle.rollover_alias
pip install pyodbc : ERROR: Command errored out with exit status 1
06 products and promotion developed by individuals - code statistical tools
Concept and basic knowledge of network layering
酷雷曼多种AI数字人形象,打造科技感VR虚拟展厅
【MySQL入门】第一话 · 初入“数据库”大陆
04 products and promotion developed by individuals - data push tool
Sqoop I have everything you want
FlutterWeb瀏覽器刷新後無法回退的解决方案
Wordcloud colormap color set and custom colors
随机推荐
How to submit data through post
03 products and promotion developed by individuals - plan service configurator v3.0
C WinForm series button easy to use
Huawei certified cloud computing hica
Unity粒子特效系列-闪星星的宝箱
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
Display picture of DataGridView cell in C WinForm
After entering Alibaba for the interview and returning with a salary of 35K, I summarized an interview question of Alibaba test engineer
06 products and promotion developed by individuals - code statistical tools
Flink analysis (I): basic concept analysis
EasyCVR平台通过接口编辑通道出现报错“ID不能为空”,是什么原因?
遠程代碼執行滲透測試——B模塊測試
The art of Engineering (3): do not rely on each other between functions of code robustness
Wordcloud colormap color set and custom colors
TCP连接不止用TCP协议沟通
历史上的今天:Google 之母出生;同一天诞生的两位图灵奖先驱
EasyCVR接入设备开启音频后,视频无法正常播放是什么原因?
The art of Engineering
SAP UI5 框架的 manifest.json
Optimization of middle alignment of loading style of device player in easycvr electronic map