若有主键,又该如何查找呢?
谢谢能有大神能解决,谢谢
3 个解决方案
#1
SELECT a, b
FROM t
WHERE (a, b) IN (SELECT a, b FROM t GROUP BY a, b HAVING COUNT(1) > 1);
SELECT id, a, b
FROM t
WHERE (a, b) IN (SELECT a, b FROM t GROUP BY a, b HAVING COUNT(1) > 1);
FROM t
WHERE (a, b) IN (SELECT a, b FROM t GROUP BY a, b HAVING COUNT(1) > 1);
SELECT id, a, b
FROM t
WHERE (a, b) IN (SELECT a, b FROM t GROUP BY a, b HAVING COUNT(1) > 1);
#2
select a.sum,b.* from (select *,count(*) as sum from table group by {全字段}) as a inner join table as b on a.user_id=a.user_id ,{全字段} where a.sum>1;
#3
select
a.id,
b.id
from
tableName a
inner join tableName b on a.id<>b.ID and a.columnA = b.columnA and a.ColumnB = b.ColumnB
a.id,
b.id
from
tableName a
inner join tableName b on a.id<>b.ID and a.columnA = b.columnA and a.ColumnB = b.ColumnB
#1
SELECT a, b
FROM t
WHERE (a, b) IN (SELECT a, b FROM t GROUP BY a, b HAVING COUNT(1) > 1);
SELECT id, a, b
FROM t
WHERE (a, b) IN (SELECT a, b FROM t GROUP BY a, b HAVING COUNT(1) > 1);
FROM t
WHERE (a, b) IN (SELECT a, b FROM t GROUP BY a, b HAVING COUNT(1) > 1);
SELECT id, a, b
FROM t
WHERE (a, b) IN (SELECT a, b FROM t GROUP BY a, b HAVING COUNT(1) > 1);
#2
select a.sum,b.* from (select *,count(*) as sum from table group by {全字段}) as a inner join table as b on a.user_id=a.user_id ,{全字段} where a.sum>1;
#3
select
a.id,
b.id
from
tableName a
inner join tableName b on a.id<>b.ID and a.columnA = b.columnA and a.ColumnB = b.ColumnB
a.id,
b.id
from
tableName a
inner join tableName b on a.id<>b.ID and a.columnA = b.columnA and a.ColumnB = b.ColumnB