Hive 其中部门项目总数大于总项目数的40%

Hive 其中部门项目总数大于总项目数的40%,hive,hiveql,Hive,Hiveql,我在hive数据库中有一个HR表,它有不同的列,其中两个是department和number of the the of the of the the of the the of the of the the of the the the Project。我需要找到的查询是“哪个部门的项目总数大于整个项目的10%” 我编写了如下代码: SELECT department, SUM(Number_Of_projects) as total_projects_dep FROM

我在hive数据库中有一个HR表,它有不同的列,其中两个是department和number of the the of the of the the of the the of the of the the of the the the Project。我需要找到的查询是“哪个部门的项目总数大于整个项目的10%”

我编写了如下代码:

SELECT department, 
       SUM(Number_Of_projects) as total_projects_dep 
  FROM Hr 
 GROUP BY department 
HAVING SUM(Number_Of_projects) > (SELECT CAST(0.1*SUM(Number_Of_projects)AS INT) FROM hr);
配置单元正在引发以下错误:

失败:ParseException行1:126无法识别“SELECT”附近的输入 表达式规范中的“强制转换”()

我在mysql中执行的同一个查询,工作正常,结果正确。而hive不接受大于symbol的查询


有人能指导我如何更改上述查询以在hive中工作。

使用分析功能:

SELECT department, total_projects_dep 
FROM       
(
SELECT department, 
       SUM(Number_Of_projects) over(partition by department) as total_projects_dep, 
       SUM(Number_Of_projects) over()                        as total_projects
  FROM Hr
)s
WHERE total_projects_dep > CAST(0.1*total_projects AS INT)
GROUP BY department, total_projects_dep --this can be removed if there is only one record per department
)