我在 Hive (SQL) 中遇到大数据问题。
SELECT genre, COUNT(*) AS unique_count
FROM table_name
GROUP BY genre
结果如下:
genre | unique_count
----------------------------------
Romance,Crime,Drama,Law | 1560
Crime,Drama,Law,Romance | 895
Law,Romance,Crime,Drama | 942
Adventure,Action | 3250
Action,Adventure | 910
我想要的是按 genre ASC|DESC 对元素进行排序并得到如下结果
genre | unique_count
----------------------------------
Crime,Drama,Law,Romance | 3397
Action,Adventure | 4160
我可以在 Python 中执行此操作,但我有超过 2 亿
行数据。我不知道有什么合理的方法可以移动这些数据。
那么我该如何实现呢?
最佳答案
select concat_ws(',',sort_array(split(genre,','))) as genre
,count(*) as unique_count
from table_name
group by concat_ws(',',sort_array(split(genre,',')))
关于sql - (Hive, SQL) - 如何对列内的字符串列表进行排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42167811/