当前位置:网站首页>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
边栏推荐
- 2022-2028 global aircraft head up display (HUD) industry research and trend analysis report
- Redis on local access server
- Fedora 21 安装 LAMP 主机服务器
- Keepalived 设置不抢占资源
- Win32: dump file analysis of heap corruption
- [combinatorics] generating function (shift property)
- How to expand the capacity of golang slice slice
- An academic paper sharing and approval system based on PHP for computer graduation design
- Sensor 调试流程
- Image 24 bit depth to 8 bit depth
猜你喜欢
Win32: analyse du fichier dump pour la défaillance du tas
Classroom attendance system based on face recognition tkinter+openpyxl+face_ recognition
Have you learned the correct expression posture of programmers on Valentine's day?
基于人脸识别的课堂考勤系统 tkinter+openpyxl+face_recognition
2022-2028 global petroleum pipe joint industry research and trend analysis report
English grammar_ Noun classification
Redis core technology and practice - learning notes (VI) how to achieve data consistency between master and slave Libraries
Naoqi robot summary 27
Valentine's day, send you a little red flower~
What problems can cross-border e-commerce sellers solve with multi platform ERP management system
随机推荐
[Tongxin UOS] scanner device management driver installation
Use of unsafe class
Image 24 bits de profondeur à 8 bits de profondeur
Lesson 13 of the Blue Bridge Cup -- tree array and line segment tree [exercise]
[combinatorics] exponential generating function (properties of exponential generating function | exponential generating function solving multiple set arrangement)
Investigation on the operation prospect of the global and Chinese Anti enkephalinase market and analysis report on the investment strategy of the 14th five year plan 2022-2028
The number of incremental paths in the grid graph [dfs reverse path + memory dfs]
win32:堆破坏的dump文件分析
[Yu Yue education] family education SPOC class 2 reference materials of Shanghai Normal University
The vscode code is automatically modified to a compliance code when it is formatted and saved
Classroom attendance system based on face recognition tkinter+openpyxl+face_ recognition
2022-2028 global plasmid DNA cdmo industry research and trend analysis report
Change the single node of Postgres database into master-slave
模块九作业
[combinatorics] generating function (example of using generating function to solve the number of solutions of indefinite equation)
Computer graduation design PHP makeup sales Beauty shopping mall
[combinatorics] generating function (property summary | important generating function)*
Fedora 21 安装 LAMP 主机服务器
Image 24 bit depth to 8 bit depth
Postfix 技巧和故障排除命令