0

我有一个包含这样列的表:

serial_id   season  ep_id
1           1       1   < duplicate
1           1       2
3           1       1
...
1           1       1   < duplicate

我想选择在 serial_id、season 和 ep_id 中具有重复值的所有行,我应该使用什么查询?谢谢。

4

2 回答 2

2

“..serial_id、season 和 ep_id 中的重复值。”

SELECT  serial_id, ep_id, season
FROM    tableName
GROUP   BY serial_id, ep_id, season
HAVING  COUNT(*) > 1

但是如果您想获取行内的所有列(*假设您有除 serial_id、ep_id、season 之外的其他列*)

SELECT  a.*
FROM    tableName a
        INNER JOIN
        (
            SELECT  serial_id, ep_id, season
            FROM    tableName
            GROUP   BY serial_id, ep_id, season
            HAVING  COUNT(*) > 1
        ) b ON  a.serial_id = b.serial_id AND
                a.ep_id = b.ep_id AND
                a.season = b.season
于 2013-02-17T14:20:18.867 回答
1

像这样的东西:

select serial_id, season, ep_id, count(*) records
from yourtable
group by serial_id, season, ep_id
having count(*) > 1
于 2013-02-17T14:20:34.017 回答