当前位置:网站首页>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
边栏推荐
- How to use scroll bars to dynamically adjust parameters in opencv
- The art of Engineering
- Wechat applet obtains mobile number
- Flink parsing (III): memory management
- 06 products and promotion developed by individuals - code statistical tools
- Debug xv6
- 【MySQL入门】第一话 · 初入“数据库”大陆
- Integrated development management platform
- 网络分层概念及基本知识
- How to output special symbols in shell
猜你喜欢
C WinForm series button easy to use
The NTFS format converter (convert.exe) is missing from the current system
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
RepPoints:可形变卷积的进阶
Flink parsing (IV): recovery mechanism
基本磁盘与动态磁盘 RAID磁盘冗余阵列区分
Automatic operation and maintenance sharp weapon ansible Foundation
历史上的今天:Google 之母出生;同一天诞生的两位图灵奖先驱
Flink parsing (III): memory management
在一台服务器上部署多个EasyCVR出现报错“Press any to exit”,如何解决?
随机推荐
MySQL advanced (index, view, stored procedure, function, password modification)
Flink parsing (III): memory management
Interpretation of Flink source code (II): Interpretation of jobgraph source code
【ASM】字节码操作 ClassWriter 类介绍与使用
Display picture of DataGridView cell in C WinForm
SQL statement optimization, order by desc speed optimization
78 岁华科教授逐梦 40 载,国产数据库达梦冲刺 IPO
The art of Engineering (3): do not rely on each other between functions of code robustness
Binary search strategy
[rapid environment construction] openharmony 10 minute tutorial (cub pie)
Flink parsing (VII): time window
Run xv6 system
Vscode replaces commas, or specific characters with newlines
Remote code execution penetration test - B module test
学 SQL 必须了解的 10 个高级概念
Summary of Android interview questions of Dachang in 2022 (II) (including answers)
MySQL stored procedure
MySQL error reporting solution
网络分层概念及基本知识
Sqoop I have everything you want