我有一个结构如下的表,我需要汇总每个系统的结果。
system st_cd tblnm
PDM_TEST FINAL CLAIM
PDM_TEST EXPIRED CLAIM
PDM_TEST COLD CLAIM
PDM_TEST WARM CLAIM
PDM_TEST HOT CLAIM
ADM_TEST COLD CLAIM
ADM_TEST WARM CLAIM
ADM_TEST HOT CLAIM
JDM_TEST HOT CLAIM
PDM_TEST HOT PROVDR
PDM_TEST WARM PROVDR
ADM_TEST EXPIRED PROVDR
ADM_TEST COLD PROVDR
ADM_TEST WARM PROVDR
ADM_TEST HOT PROVDR
JDM_TEST WARM PROVDR
JDM_TEST HOT PROVDR
如果系统在表之间只有热,热,冷st_cd,则说明系统符合标准。如果系统已过期或最终,则其不符合要求。
汇总后,预期输出如下。我如何在Impala sql中实现此目标?
PDM_TEST NON-COMPLIANT
ADM_TEST NON-COMPLIANT
JDM_TEST COMPLIANT
答案 0 :(得分:0)
您可以使用条件聚合:
select system,
(case when sum(case when st_cd not in ('HOT', 'WARM', 'COLD') then 1 else 0 end) > 0
then 'NON-COMPLIANT'
else 'COMPLIANT'
end) as status
from t
group by system;