首页 > 解决方案 > 如何在oracle sql中对已经分组的数据集进行分组

问题描述

问题数据集

预期产出

我想首先根据“Roll”对数据进行分组,然后根据“名称”将其进一步分组,并使用不同的“标记”。我已经使用Group by 和 have 对数据进行了分组,但我不确定如何进一步对其进行分组。

标签: sqloracle

解决方案


如果我理解正确,您希望roll/name对具有多个不同的值。您可以使用窗口函数执行此操作:

select distinct roll, name, marks
from (select t.*, count(distinct marks) over (partition by roll, name) as cnt
      from t
     ) t
where cnt > 1;

推荐阅读