配置单元获取计数列的百分比不起作用

hive get percentages of count column not working

我在配置单元中有以下查询,以获取每个列(集群、国家和航空公司)的计数百分比。但是我的百分比列只包含 0.. why/what 我在下面做错了吗?

 select 
    
        count(*)/ t.cnt * 100 AS percentage,
        cluster,
        country,
        airline 
        from 

        table1
 CROSS JOIN (SELECT COUNT(*) AS cnt FROM table1 ) t
 GROUP
    BY cluster,
        country,
        airline 

首先,您应该使用 window 函数。

其次,谨防整数除法

我会这样表述:

select count(*) * 100.0 / sum(count(*)) over ()  AS percentage,
       cluster, country, airline 
from table1
group by cluster, country, airline;