当前位置:网站首页>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
边栏推荐
- Unsafe类的使用
- Three gradient descent methods and code implementation
- 2022-2028 global solid phase extraction column industry research and trend analysis report
- How to track the real-time trend of Bank of London
- English grammar_ Adjective / adverb Level 3 - multiple expression
- win32:堆破壞的dump文件分析
- 图像24位深度转8位深度
- Golang string (string) and byte array ([]byte) are converted to each other
- [combinatorics] generating function (positive integer splitting | unordered non repeated splitting example)
- Design limitations of structure type (struct)
猜你喜欢
Sensor 调试流程
English语法_名词 - 分类
Win32: analyse du fichier dump pour la défaillance du tas
English语法_形容词/副词3级 - 倍数表达
How to analyze the rising and falling rules of London gold trend chart
Lesson 13 of the Blue Bridge Cup -- tree array and line segment tree [exercise]
English grammar_ Adjective / adverb Level 3 - multiple expression
AcWing 271. Teacher Yang's photographic arrangement [multidimensional DP]
Prototype inheritance..
2022-2028 global solid phase extraction column industry research and trend analysis report
随机推荐
198. Looting - Dynamic Planning
Sensor 调试流程
分布式的任务分发框架-Gearman
2022-2028 global physiotherapy clinic industry research and trend analysis report
[combinatorics] exponential generating function (concept of exponential generating function | permutation number exponential generating function = combinatorial number ordinary generating function | e
企业级自定义表单引擎解决方案(十二)--表单规则引擎2
Win 11 major updates, new features love love.
Have you learned the correct expression posture of programmers on Valentine's day?
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
Line by line explanation of yolox source code of anchor free series network (5) -- mosaic data enhancement and mathematical understanding
[combinatorics] generating function (use generating function to solve the number of solutions of indefinite equation example 2 | extended to integer solution)
Ml (machine learning) softmax function to realize the classification of simple movie categories
Fedora 21 installs lamp host server
Global and Chinese pediatric palliative care drug market development research and investment planning recommendations report 2022-2028
Research Report on competitive strategy Outlook Analysis and investment strategic planning of China's smart home equipment industry, 2022-2028
Micro service component sentinel console call
A. Berland Poker & 1000 [simple mathematical thinking]
2022-2028 global petroleum pipe joint industry research and trend analysis report
[combinatorics] exponential generating function (properties of exponential generating function | exponential generating function solving multiple set arrangement)
【统信UOS】扫描仪设备管理驱动安装