当前位置:网站首页>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 
边栏推荐
- SQL injection -day16
- PHP MySQL create database
- [combinatorics] generating function (shift property)
- Kotlin的協程:上下文
- Kotlin's collaboration: Context
- Ssl/bio of OpenSSL_ get_ fd
- [tutorial] build your first application on coreos
- Applet with multiple tabs and Swipers + paging of each tab
- 小程序 多tab 多swiper + 每个tab分页
- 2022-2028 global solid phase extraction column industry research and trend analysis report
猜你喜欢

How to deploy applications on kubernetes cluster

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

Win 11 major updates, new features love love.

Ml (machine learning) softmax function to realize the classification of simple movie categories

On Data Mining

Module 9 operation

Codeforces Round #803 (Div. 2) C. 3SUM Closure

What kind of experience is it when the Institute earns 20000 yuan a month?

2022-2028 global physiotherapy clinic industry research and trend analysis report

Install apache+php+mysql+phpmyadmin xampp and its error resolution
随机推荐
圖像24比特深度轉8比特深度
Count the number of pixel values in the image
[Godot] add menu button
Sensor debugging process
[combinatorics] generating function (commutative property | derivative property | integral property)
The second largest gay dating website in the world was exposed, and the status of programmers in 2022
198. Looting - Dynamic Planning
Keepalived setting does not preempt resources
[combinatorics] generating function (positive integer splitting | repeated ordered splitting | non repeated ordered splitting | proof of the number of repeated ordered splitting schemes)
企业级自定义表单引擎解决方案(十二)--表单规则引擎2
Bidding procurement scheme management of Oracle project management system
Coordinate layer conversion tool (video)
PHP MySQL Update
What problems can cross-border e-commerce sellers solve with multi platform ERP management system
How to draw non overlapping bubble chart in MATLAB
win32:堆破坏的dump文件分析
Sensor 调试流程
Design limitations of structure type (struct)
Computer graduation design PHP sports goods online sales system website
Win 11 major updates, new features love love.