1

鉴于我有列 ABCD ..... Z

我想对具有 Count(*) > 1 的 A、B、C 进行分组,然后对于这些行中的每一行,我还想选择未包含在聚合中的其余列。

结果就像

Occurrences    A   B   C    D   E   F    G  ------- Z
3              e   e   k    q   r   y    e  ------- j
3              e   e   k    f   t   d    t  ------- y
3              e   e   k    w   e   q    c  ------- d
2              f   r   s    w   e   q    c  ------- d
2              f   r   s    w   e   q    c  ------- d

我怎样才能做到这一点?

4

1 回答 1

1

你不想要GROUP BY,你想要ORDER BY。要获取第一列,您可以使用窗口函数,它是 ANSI 标准并且大多数数据库都支持:

select t.*
from (select count(*) over (partition by a, b, c) as occurrences,
             t.*
      from t
      order by a, b, c
     ) t
where occurrences > 1;
于 2015-10-23T15:07:10.587 回答