当前位置:网站首页>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 
边栏推荐
- (8) HS corner detection
- Niuke monthly race 31 minus integer
- win32:堆破坏的dump文件分析
- PHP MySQL inserts data
- [combinatorics] generating function (positive integer splitting | unordered | ordered | allowed repetition | not allowed repetition | unordered not repeated splitting | unordered repeated splitting)
- Setinterval CPU intensive- Is setInterval CPU intensive?
- Gear2021 monthly update - December
- [combinatorics] exponential generating function (proving that the exponential generating function solves the arrangement of multiple sets)
- OpenSSL的SSL/BIO_get_fd
- On Data Mining
猜你喜欢

How to install PHP on Ubuntu 20.04

G1 garbage collector of garbage collector

Global and Chinese health care OEM and ODM market status survey and investment planning recommendations report 2022-2028

How to draw non overlapping bubble chart in MATLAB

2022-2028 global plasmid DNA cdmo industry research and trend analysis report

AcWing 271. 杨老师的照相排列【多维DP】

Three gradient descent methods and code implementation

2022-2028 global marking ink industry research and trend analysis report

win32:堆破坏的dump文件分析

2022-2028 global copper foil (thickness 12 μ M) industry research and trend analysis report
随机推荐
How to track the real-time trend of Bank of London
Kotlin的協程:上下文
[combinatorics] generating function (use generating function to solve the number of solutions of indefinite equation example 2 | extended to integer solution)
PHP MySQL inserts data
Postfix 技巧和故障排除命令
How to expand the capacity of golang slice slice
English语法_名词 - 分类
SDNUOJ1015
[linux]centos 7 reports an error when installing MySQL "no package MySQL server available" no package ZABBIX server MySQL available
[Godot] add menu button
Classroom attendance system based on face recognition tkinter+openpyxl+face_ recognition
Unsafe类的使用
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
Grammaire anglaise Nom - Classification
Computer graduation project PHP library book borrowing management system
198. Looting - Dynamic Planning
4. Load balancing and dynamic static separation
What problems can cross-border e-commerce sellers solve with multi platform ERP management system
Summary and Reflection on the third week of winter vacation
Introduction to PHP MySQL