我有以下数据:
col_1 | col_2 | col_3 | col_4
-----------------------------
a1 b1 c1 d1
a1 b2 c1 d1
a1 b3 c1 d1
a1 b4 c1 d2
a1 b5 c2 d2
a1 b6 c2 d2
a1 b7 c1 d3
a1 b8 c2 d3
a1 b9 c3 d3
a1 b10 c1 d2
a1 b11 c2 d3
a2 b12 c1 d1
a3 b13 c1 d1
我有兴趣能够:
col_1
的值唯一的行col_3
,col_4
例如,我希望输出返回以下内容:
col_1 | col_2 | col_3 | col_4
-----------------------------
a1 b1 c1 d1
a2 b12 c1 d1
a3 b13 c1 d1
注意,结果col_1
中的每个值都是唯一的。还请注意,对于a1
,它以c1
和d1
返回,因为它们的a1
计数最高。
如何通过SQL查询实现这一目标?我将使用它进行Hive SQL查询。
我有以下数据:col_1 | col_2 | col_3 | col_4 ----------------------------- a1 b1 c1 d1 a1 b2 c1 d1 a1 b3 c1 d1 a1 b4 c1 d2 a1 ...
您可以使用聚合和窗口功能:
具有row_number()
窗口功能: