当前位置:网站首页>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
边栏推荐
- Establishment of graphical monitoring grafana
- 传统家装有落差,VR全景家装让你体验新房落成效果
- [introduction to MySQL] third, common data types in MySQL
- Vscode replaces commas, or specific characters with newlines
- Chrome prompts the solution of "your company management" (the startup page is bound to the company's official website and cannot be modified)
- Shell input a string of numbers to determine whether it is a mobile phone number
- OpenCV中如何使用滚动条动态调整参数
- Example of batch update statement combining update and inner join in SQL Server
- How to output special symbols in shell
- EasyCVR接入设备开启音频后,视频无法正常播放是什么原因?
猜你喜欢
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
开源与安全的“冰与火之歌”
The NTFS format converter (convert.exe) is missing from the current system
【MySQL入门】第一话 · 初入“数据库”大陆
Unity particle special effects series - treasure chest of shining stars
历史上的今天:Google 之母出生;同一天诞生的两位图灵奖先驱
Selenium test of automatic answer runs directly in the browser, just like real users.
【MySQL入门】第三话 · MySQL中常见的数据类型
RepPoints:可形变卷积的进阶
Interpretation of Flink source code (II): Interpretation of jobgraph source code
随机推荐
[translation] principle analysis of X Window Manager (I)
Unity小技巧 - 绘制瞄准准心
MySQL 8 sub database and table backup database shell script
Application service configurator (regular, database backup, file backup, remote backup)
Development and practice of lightweight planning service tools
Wordcloud colormap color set and custom colors
The solution that flutterweb browser cannot be rolled back after refreshing
虚拟机启动提示Probing EDD (edd=off to disable)错误
The NTFS format converter (convert.exe) is missing from the current system
In terms of byte measurement with an annual salary of 30W, automated testing can be learned in this way
当前系统缺少NTFS格式转换器(convert.exe)
Reppoints: advanced order of deformable convolution
06 products and promotion developed by individuals - code statistical tools
C# NanoFramework 点灯和按键 之 ESP32
基于STM32+华为云IOT设计的智能路灯
PySpark算子处理空间数据全解析(4): 先说说空间运算
BearPi-HM_ Nano development environment
MySQL advanced (index, view, stored procedure, function, password modification)
Display picture of DataGridView cell in C WinForm
How uipath determines that an object is null