问题描述
错误消息:
选择列表表达式不是由聚合输出生成的(丢失 来自GROUP BY子句?):当(标志= 1)然后为date_add(lead_ctxdt, -1)ELSE ctx_date END lot_endt
代码:
select c.enrolid,c.ctx_date,c.ctx_regimen,c.lead_ctx,c.lead_ctxdt,min(c.ctx_date) as lot_stdt,case when (flag = 1 ) then date_add(lead_ctxdt,-1)
else ctx_date
end as lot_endt
from
(
select p.*,case when (ctx_regimen <> lead_ctx) then 1
else 0
end as flag
from
(
select a.*,lead(a.ctx_regimen,1) over(partition by enrolid order by ctx_date) as lead_ctx,lead(ctx_date,1) over (partition by enrolid order by ctx_date) as lead_ctxdt
from
(
select enrolid,ctx_date,group_concat(distinct ctx_codes) as ctx_regimen
from lotinfo
where ctx_date between ctx_date and date_add(ctx_date,5)
group by enrolid,ctx_date
) as a
) as p
) as c
group by c.enrolid,c.lead_ctxdt
我想获取lead_ctx日期减去1作为标志为1的日期
解决方法
因此,我通过执行几次小的更改找到了答案。让我告诉您,当您尝试在同一查询中同时具有min_max和max_max时,在Impala中这是行不通的。您必须在每个子查询中的两个查询中以及在外部查询中的某物的min()中编写它,反之亦然。
谢谢@dnoeth,让我明白我已经有了答案。