计数功能和大小写

时间:2019-07-19 00:57:57

标签: sql hive bigdata hue

将第1-8阶段应计为SAL的机会数进行计数,但是我只想将第3-7阶段作为SQL过滤。

尝试了case语句,并在无效的子查询中计数。下面的代码:

SELECT camp, count(opp_id) as sal, 
count(opp_id (select opp_id from db.opp_data_q3 where stage not in ("01", "02")) as sql,
 from db.opp_data_q3 
where created_quarter = "Q3" 
group by camp;

预期结果:

Camp A | SAL 10 | SQL 5
Camp B | SAL 20 | SQL 3

实际结果是一条错误消息:

  

编译语句时出错:失败:ParseException第2:14行无法识别函数规范中'select''opp_id''from'附近的输入

1 个答案:

答案 0 :(得分:0)

我认为您只需要条件聚合:

select camp, count(*) as sal, 
       sum(case when stage not in ('01', '02') then 1 else 0 end) as sql
from db.opp_data_q3 
where created_quarter = 'Q3;
group by camp;