当前位置:网站首页>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 
边栏推荐
- The vscode code is automatically modified to a compliance code when it is formatted and saved
- Coordinate layer conversion tool (video)
- Postfix tips and troubleshooting commands
- Class exercises
- Supervisor monitors gearman tasks
- 204. Count prime
- Self executing function
- Mature port AI ceaspectus leads the world in the application of AI in terminals, CIMC Feitong advanced products go global, smart terminals, intelligent ports, intelligent terminals
- Introduction to PHP MySQL
- [combinatorics] generating function (positive integer splitting | basic model of positive integer splitting | disordered splitting with restrictions)
猜你喜欢

How to install PHP on Ubuntu 20.04

Line by line explanation of yolox source code of anchor free series network (5) -- mosaic data enhancement and mathematical understanding

How to track the real-time trend of Bank of London

Classroom attendance system based on face recognition tkinter+openpyxl+face_ recognition

Computer graduation design PHP makeup sales Beauty shopping mall

Research on Swift

Win32: analyse du fichier dump pour la défaillance du tas

Theoretical description of linear equations and summary of methods for solving linear equations by eigen
![Bloom filter [proposed by bloom in 1970; redis cache penetration solution]](/img/f9/27a75454b464d59b9b3465d25fe070.jpg)
Bloom filter [proposed by bloom in 1970; redis cache penetration solution]
![[combinatorics] generating function (summation property)](/img/74/e6ef8ee69ed07d62df9f213c015f2c.jpg)
[combinatorics] generating function (summation property)
随机推荐
[untitled]
(8) HS corner detection
How to draw non overlapping bubble chart in MATLAB
PHP MySQL order by keyword
Coordinate layer conversion tool (video)
Unsafe类的使用
[Yu Yue education] family education SPOC class 2 reference materials of Shanghai Normal University
Codeforces Round #803 (Div. 2) C. 3SUM Closure
[combinatorics] generating function (positive integer splitting | unordered non repeated splitting example)
Kotlin's collaboration: Context
网格图中递增路径的数目[dfs逆向路径+记忆dfs]
Line by line explanation of yolox source code of anchor free series network (5) -- mosaic data enhancement and mathematical understanding
Fedora 21 安装 LAMP 主机服务器
2022-2028 global petroleum pipe joint industry research and trend analysis report
How to analyze the rising and falling rules of London gold trend chart
Redis core technology and practice - learning notes (VIII) sentinel cluster: sentinel hung up
Count the number of pixel values in the image
Life perception 1
[combinatorics] exponential generating function (proving that the exponential generating function solves the arrangement of multiple sets)
Mature port AI ceaspectus leads the world in the application of AI in terminals, CIMC Feitong advanced products go global, smart terminals, intelligent ports, intelligent terminals