如何在 Hive 中运行 Groupby 和选择条件变量?

问题描述 投票:0回答:1

我希望根据以下条件选择条件:

SELECT income_decile, income, benefits, 
COUNT(*) FROM income_dataset WHERE income > 50000 AND benefits < 2000; 
GROUP BY income_decile;

如何运行像数据透视表那样对每个类别求和的追随者?

sql hive hue
1个回答
0
投票

要在 Hive 中实现分组和条件选择,您需要确保查询的结构化、 这是你可以做到的方法,

SELECT 
    income_decile, 
    SUM(income) AS total_income, 
    SUM(benefits) AS total_benefits, 
    COUNT(*) AS total_count
FROM 
    income_dataset 
WHERE 
    income > 50000 
    AND benefits < 2000 
GROUP BY 
    income_decile;
© www.soinside.com 2019 - 2024. All rights reserved.