mysql查询某字段相同的记录

mysql查询某字段相同的记录,第1张

select * from 表名 where match_id in (select match_id from 表名 where team_id='a' or team_id='b' group by match_id)

select * from tableName where (bookname,borrowtime) in (select bookname,borrowtime from tableName group by bookname,borrowtime having count(*) > 1)

查看可用如下方法:

1、创建测试表,插入数据

1

2

3

4

5

6

7

8

9

10

11

12

13

create table product

(id int,

name varchar(10),

totol int)

insert into product values (1,'香蕉',100)

insert into product values (2,'橘子',67)

insert into product values (3,'葡萄',89)

insert into product values (4,'苹果',235)

insert into product values (5,'香蕉',77)

insert into product values (6,'芒果',34)

insert into product values (7,'葡萄',78)

insert into product values (8,'梨',24)

表中数据如:

2、如果查询name列有重复的数据,可执行sql语句:

1

select * from product where name in (select name from product group by name having COUNT(*)>1)

说明:查询的结果就是香蕉和葡萄在表中是有重复的


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/7106421.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-01
下一篇 2023-04-01

发表评论

登录后才能评论

评论列表(0条)

保存