首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Case when表达式from Case When Result

Case when表达式from Case When Result
EN

Stack Overflow用户
提问于 2018-06-09 04:03:17
回答 1查看 95关注 0票数 0

我需要从前一个case when表达式的结果中编写一个case when表达式。

代码语言:javascript
复制
 case 
    when state = 'nj' and date >= '2018-01-01' then 'new'
    else 'existing' 
end as 'new or existing'

case
    when state = 'nj' and 'new or existing' = 'existing' and date <= '2017-12-31' 
       then 'eligible'
       else 'next time' 
end as 'eligibility'

提前谢谢你!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-09 04:09:47

嵌套的case when可以做到这一点。

代码语言:javascript
复制
(case
    when state='nj' and 
    (
    case 
        when date < '2018-01-01' then 'existing'
    end 
    )='existing' and date <= '2017-12-31' then 'eligible'
else 'next time' 
end
) as 'eligibility'

理清你的逻辑,我想你需要这个。

代码语言:javascript
复制
(case
    when state='nj' and date <= '2017-12-31' then 'eligible'
else 'next time' 
end
) as 'eligibility'

您也可以使用IIF来创建它。

代码语言:javascript
复制
IIF(state = 'nj' AND IIF(date < '2018-01-01','existing','new') ='existing' and date <= '2017-12-31' , 'eligible','next time') as 'eligibility'

IIF

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50767693

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档