当前位置:网站首页>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
边栏推荐
- 【Elastic】Elastic缺少xpack无法创建模板 unknown setting index.lifecycle.name index.lifecycle.rollover_alias
- Huawei certified cloud computing hica
- node の SQLite
- Essai de pénétration du Code à distance - essai du module b
- EasyCVR平台通过接口编辑通道出现报错“ID不能为空”,是什么原因?
- sql语句优化,order by desc速度优化
- SQL statement optimization, order by desc speed optimization
- Xin'an Second Edition; Chapter 11 learning notes on the principle and application of network physical isolation technology
- Selenium test of automatic answer runs directly in the browser, just like real users.
- MySQL Advanced (index, view, stored procedures, functions, Change password)
猜你喜欢

基于STM32+华为云IOT设计的智能路灯

Display picture of DataGridView cell in C WinForm

Establishment of graphical monitoring grafana
![[ASM] introduction and use of bytecode operation classwriter class](/img/0b/87c9851e577df8dcf8198a272b81bd.png)
[ASM] introduction and use of bytecode operation classwriter class

EasyCVR接入设备开启音频后,视频无法正常播放是什么原因?

Yarn: unable to load file d:\programfiles\nodejs\yarn PS1, because running scripts is prohibited on this system

分布式不来点网关都说不过去

BearPi-HM_ Nano development environment

Vscode replaces commas, or specific characters with newlines

The NTFS format converter (convert.exe) is missing from the current system
随机推荐
pip install pyodbc : ERROR: Command errored out with exit status 1
Essai de pénétration du Code à distance - essai du module b
基本磁盘与动态磁盘 RAID磁盘冗余阵列区分
C # nanoframework lighting and key esp32
How uipath determines that an object is null
05 personal R & D products and promotion - data synchronization tool
Binary search strategy
虚拟机启动提示Probing EDD (edd=off to disable)错误
自动化运维利器ansible基础
The art of Engineering (1): try to package things that do not need to be exposed
Mysqlimport imports data files into the database
Xin'an Second Edition: Chapter 25 mobile application security requirements analysis and security protection engineering learning notes
Easy introduction to SQL (1): addition, deletion, modification and simple query
Summary of Android interview questions of Dachang in 2022 (I) (including answers)
2022年大厂Android面试题汇总(一)(含答案)
网络分层概念及基本知识
mysql高級(索引,視圖,存儲過程,函數,修改密碼)
Debug xv6
Automatic operation and maintenance sharp weapon ansible Playbook
PySpark算子处理空间数据全解析(5): 如何在PySpark里面使用空间运算接口