我的表具有以下类型的条目:
Serial Number | Cycle Number
55 33
56 27
55 34
55 33
57 5
57 6
56 28
57 6
我想返回具有相同值的多个循环号的不同序列号
Serial Number | Cycle Number
55 33
55 33
57 6
57 6
任何帮助将不胜感激。
答案 0 :(得分:2)
您可以使用以下查询,该查询将返回具有多个具有相同值的循环编号的唯一序列号。
SELECT SerialNumber, CycleNumber
FROM Table
GROUP BY SerialNumber, CycleNumber HAVING COUNT(SerialNumber)>1
答案 1 :(得分:1)
如果您实际上只有两列,则可以这样做:
select serial, cycle
from t
where (serial, cycle) in (select serial, cycle
from t t2
group by serial, cycle
having count(*) >= 2
);
但是你为什么不这样做呢?
select serial, cycle, count(*)
from t
group by serial, cycle;
答案 2 :(得分:0)
SQL语法:
SELECT A.* FROM tmpTable A
LEFT JOIN
(
SELECT SerialNumber,CycleNumber FROM tmpTable GROUP BY SerialNumber, CycleNumber having count(SerialNumber)>1
) B ON A.SerialNumber = B.SerialNumber And A.CycleNumber = B.CycleNumber
WHERE B.SerialNumber is not null