当前位置:网站首页>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
边栏推荐
- Summary of Android interview questions of Dachang in 2022 (II) (including answers)
- 自动化运维利器-Ansible-Playbook
- 78 岁华科教授逐梦 40 载,国产数据库达梦冲刺 IPO
- 02 personal developed products and promotion - SMS platform
- Xin'an Second Edition: Chapter 25 mobile application security requirements analysis and security protection engineering learning notes
- The solution to the left-right sliding conflict caused by nesting Baidu MapView in the fragment of viewpager
- Openharmony developer documentation open source project
- 开源与安全的“冰与火之歌”
- Establishment of graphical monitoring grafana
- The solution that flutterweb browser cannot be rolled back after refreshing
猜你喜欢
Flink parsing (VII): time window
基本磁盘与动态磁盘 RAID磁盘冗余阵列区分
Pyspark operator processing spatial data full parsing (4): let's talk about spatial operations first
C WinForm series button easy to use
Yarn: unable to load file d:\programfiles\nodejs\yarn PS1, because running scripts is prohibited on this system
Chrome prompts the solution of "your company management" (the startup page is bound to the company's official website and cannot be modified)
TCP connection is more than communicating with TCP protocol
历史上的今天:Google 之母出生;同一天诞生的两位图灵奖先驱
【ASM】字节码操作 ClassWriter 类介绍与使用
Start job: operation returned an invalid status code 'badrequst' or 'forbidden‘
随机推荐
【ASM】字节码操作 ClassWriter 类介绍与使用
C# NanoFramework 点灯和按键 之 ESP32
Kali2021 installation and basic configuration
Binary search strategy
Xin'an Second Edition: Chapter 25 mobile application security requirements analysis and security protection engineering learning notes
Spark calculation operator and some small details in liunx
Selenium test of automatic answer runs directly in the browser, just like real users.
Pyspark operator processing spatial data full parsing (5): how to use spatial operation interface in pyspark
In terms of byte measurement with an annual salary of 30W, automated testing can be learned in this way
connection reset by peer
MySQL error reporting solution
BearPi-HM_ Nano development board "flower protector" case
The art of Engineering (3): do not rely on each other between functions of code robustness
MySQL报错解决
How to output special symbols in shell
Quick start of Hongmeng system
78 岁华科教授逐梦 40 载,国产数据库达梦冲刺 IPO
【MySQL入门】第一话 · 初入“数据库”大陆
开源与安全的“冰与火之歌”
【Elastic】Elastic缺少xpack无法创建模板 unknown setting index.lifecycle.name index.lifecycle.rollover_alias