需要在一列上进行 groupby 添加获取 Hive 中其他列的计数
Need to groupby on one column add get the count of other column in Hive
这是我的示例数据:
在上面table中,我们可以看到a1,a2,a3,a4都有src1。我只需要 a3 和 a4 作为结果,因为它们是唯一嵌入了 src1 的行。 a1 和 a2 有其他 src2,...等
我需要一个配置单元查询来获取结果。
您可以按 col1
聚合,并使用 having
子句过滤 col1
,其 col2
的唯一值为 'src1'
。
select col1
from mytable
group by col1
having min(col2) = max(col2) and min(col2) = 'src1'
这是我的示例数据:
在上面table中,我们可以看到a1,a2,a3,a4都有src1。我只需要 a3 和 a4 作为结果,因为它们是唯一嵌入了 src1 的行。 a1 和 a2 有其他 src2,...等
我需要一个配置单元查询来获取结果。
您可以按 col1
聚合,并使用 having
子句过滤 col1
,其 col2
的唯一值为 'src1'
。
select col1
from mytable
group by col1
having min(col2) = max(col2) and min(col2) = 'src1'