当前位置:网站首页>MySQL duplicate check
MySQL duplicate check
2022-07-03 18:21:00 【wgchen~】
Read the directory
MySQL data
CREATE TABLE `test` (
`Id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(25) DEFAULT NULL COMMENT ' title ',
`uid` int(11) DEFAULT NULL COMMENT 'uid',
`money` decimal(2,0) DEFAULT '0',
`name` varchar(25) DEFAULT NULL,
PRIMARY KEY (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4;
INSERT INTO `demo`.`test` (`Id`, `title`, `uid`, `money`, `name`) VALUES ('2', ' National Day ', '2', '12', ' Zhou Bo Tong ');
INSERT INTO `demo`.`test` (`Id`, `title`, `uid`, `money`, `name`) VALUES ('3', ' This time it is 8 Oh, oh! ', '3', '33', ' Old urchin ');
INSERT INTO `demo`.`test` (`Id`, `title`, `uid`, `money`, `name`) VALUES ('4', ' This is a Uid=1 The first data of ', '1', '70', ' Ouyang Feng ');
INSERT INTO `demo`.`test` (`Id`, `title`, `uid`, `money`, `name`) VALUES ('5', ' Young master of lingbai mountain ', '4', '99', ' Ouyang grams ');
INSERT INTO `demo`.`test` (`Id`, `title`, `uid`, `money`, `name`) VALUES ('7', ' Founder of the nine Yin Scripture ', '3', '12', ' Little naughty boy ');
INSERT INTO `demo`.`test` (`Id`, `title`, `uid`, `money`, `name`) VALUES ('8', ' Hands to each other ', '2', '56', ' Zhou Bo Tong ');
INSERT INTO `demo`.`test` (`Id`, `title`, `uid`, `money`, `name`) VALUES ('9', ' National Day ', '2', '19', ' Zhou Bo Tong ');
INSERT INTO `demo`.`test` (`Id`, `title`, `uid`, `money`, `name`) VALUES ('10', ' The toad style of Kwan Lun school ', '1', '57', ' Ouyang Feng ');
INSERT INTO `demo`.`test` (`Id`, `title`, `uid`, `money`, `name`) VALUES ('11', ' Young master of lingbai mountain ', NULL, '0', ' Ouyang grams ');
INSERT INTO `demo`.`test` (`Id`, `title`, `uid`, `money`, `name`) VALUES ('12', ' National Day ', '2', '12', ' Zhou Bo Tong ');

Single field query statement
select * from test where title in
(select title from test group by title having count(title) > 1)

SELECT COUNT(*),`title`,`uid` FROM `test`
GROUP BY `title` HAVING count(*) > 1;

SELECT *,COUNT(0) as c FROM `test` GROUP BY `title`;

SELECT *,COUNT(1) as c FROM `test` GROUP BY `title` HAVING c > 1;

select count(title) as ' Repeat the number ',title from test
group by title having count(*)>1 order by title desc

Multiple field duplicate record query
INSERT INTO `demo`.`test` (`Id`, `title`, `uid`, `money`, `name`) VALUES ('2', ' National Day ', '2', '12', ' Zhou Bo Tong ');
INSERT INTO `demo`.`test` (`Id`, `title`, `uid`, `money`, `name`) VALUES ('3', ' This time it is 8 Oh, oh! ', '3', '33', ' Old urchin ');
INSERT INTO `demo`.`test` (`Id`, `title`, `uid`, `money`, `name`) VALUES ('4', ' This is a Uid=1 The first data of ', '1', '70', ' Ouyang Feng ');
INSERT INTO `demo`.`test` (`Id`, `title`, `uid`, `money`, `name`) VALUES ('5', ' Young master of lingbai mountain ', '4', '99', ' Ouyang grams ');
INSERT INTO `demo`.`test` (`Id`, `title`, `uid`, `money`, `name`) VALUES ('7', ' Founder of the nine Yin Scripture ', '3', '12', ' Little naughty boy ');
INSERT INTO `demo`.`test` (`Id`, `title`, `uid`, `money`, `name`) VALUES ('8', ' Hands to each other ', '2', '56', ' Zhou Bo Tong ');
INSERT INTO `demo`.`test` (`Id`, `title`, `uid`, `money`, `name`) VALUES ('9', ' National Day ', '2', '19', ' Zhou Bo Tong ');
INSERT INTO `demo`.`test` (`Id`, `title`, `uid`, `money`, `name`) VALUES ('10', ' The toad style of Kwan Lun school ', '1', '57', ' Ouyang Feng ');
INSERT INTO `demo`.`test` (`Id`, `title`, `uid`, `money`, `name`) VALUES ('11', ' Young master of lingbai mountain ', NULL, '0', ' Ouyang grams ');
INSERT INTO `demo`.`test` (`Id`, `title`, `uid`, `money`, `name`) VALUES ('12', ' National Day ', '2', '12', ' Zhou Bo Tong ');
INSERT INTO `demo`.`test` (`Id`, `title`, `uid`, `money`, `name`) VALUES ('13', ' Founder of the nine Yin Scripture ', '3', '0', ' Little naughty boy ');

select
*
from
test t
where
(
select count(1) from test where t.title = title
AND
t.uid = uid
)>1 ORDER BY t.title

UPDATE `test` SET `money`='12' WHERE (`Id`='13')

SELECT
title, count(title) as title_num,
uid, count(uid) as uid_num
FROM
test
GROUP BY
title,
uid
HAVING
(count(title) > 1)

select * from test a
where
(a.title,a.uid) in
(select title,uid from test group by title,uid having count(*) > 1)

SELECT
title, count(title) as title_num,
uid, count(uid) as uid_num
FROM
test
GROUP BY
title,
uid
HAVING
(count(title) > 1)

All data 
SELECT * FROM test
WHERE
(
title IN (SELECT title FROM test GROUP BY title,uid,money HAVING COUNT(*)>1)
AND
uid IN (SELECT uid FROM test GROUP BY title,uid,money HAVING COUNT(*)>1)
AND
money IN (SELECT money FROM test GROUP BY title,uid,money HAVING COUNT(*)>1)
)

All data 
边栏推荐
- Sensor debugging process
- 2022-2028 global plasmid DNA cdmo industry research and trend analysis report
- SQL injection -day16
- Research on Swift
- What London Silver Trading software supports multiple languages
- 199. Right view of binary tree - breadth search
- Lesson 13 of the Blue Bridge Cup -- tree array and line segment tree [exercise]
- On Data Mining
- 2022-2028 global scar care product industry research and trend analysis report
- win32:堆破壞的dump文件分析
猜你喜欢

基于人脸识别的课堂考勤系统 tkinter+openpyxl+face_recognition

4. Load balancing and dynamic static separation

How to draw non overlapping bubble chart in MATLAB

PHP MySQL create database
![[untitled]](/img/83/5a57ed90aaafde94db600246256867.jpg)
[untitled]

win32:堆破坏的dump文件分析

On Data Mining

How to deploy applications on kubernetes cluster

Global and Chinese pediatric palliative care drug market development research and investment planning recommendations report 2022-2028

What problems can cross-border e-commerce sellers solve with multi platform ERP management system
随机推荐
(9) Opencv Canny edge detection
Enterprise custom form engine solution (12) -- form rule engine 2
[combinatorics] generating function (use generating function to solve the number of solutions of indefinite equation)
Coordinate layer conversion tool (video)
Lesson 13 of the Blue Bridge Cup -- tree array and line segment tree [exercise]
【统信UOS】扫描仪设备管理驱动安装
[untitled]
A. Berland Poker & 1000 [simple mathematical thinking]
Life perception 1
Research Report on competitive strategy Outlook Analysis and investment strategic planning of China's smart home equipment industry, 2022-2028
The second largest gay dating website in the world was exposed, and the status of programmers in 2022
Setinterval CPU intensive- Is setInterval CPU intensive?
199. Right view of binary tree - breadth search
Market demand survey and marketing strategy analysis report of global and Chinese pet milk substitutes 2022-2028
WebView module manages the application window interface to realize the logical control and management operation of multiple windows (Part 1)
OpenSSL的SSL/BIO_get_fd
Nodejs (01) - introductory tutorial
Analysis report on production and marketing demand and investment forecast of China's PVC industry from 2021 to 2026
Naoqi robot summary 27
2022-2028 global solid phase extraction column industry research and trend analysis report