我想计算Hive中几列的基数。
例如,表格就像
------------------------------------------
| A | B | C | D |
------------------------------------------
| Windows | C:\Users\aa | 0 | 1234 |
------------------------------------------
| Windows | D:\Videos | 1 | 2345 |
------------------------------------------
| Linux | /usr/local | 0 | 1234 |
------------------------------------------
| OS X | /Users/aa | 0 | 5678 |
------------------------------------------
A,C,D列的基数为3、2、3。
天真的解决方案是在每列上运行
SELECT DISTINCT
。但是,这似乎是一种可怕的方式。那么是否可以通过仅扫描表一次来计算这些值?
最佳答案
如果只希望每列的唯一计数,则可以使用count distinct
select
count(distinct a),
count(distinct c),
count(distinct d)
from mytable
关于hadoop - 我可以区分Hive中的每一列吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25989912/