首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >嵌套的"CASE when“语句

问嵌套的"CASE when“语句
EN

Stack Overflow用户
提问于 2012-05-16 06:58:41
回答 1查看 56.8K关注 0票数 2

如何在sql查询中使用'case‘语句的嵌套形式。我正在尝试执行以下查询。

代码语言:javascript
复制
SELECT AccessTabF1.Month, AccessTabF1.Year, AccessTabF1.[Entity Number], 
case when [Exp Year]= 2010 + 1
     then 'Expires in 1 to 5 Years'
     else
          case when [Exp Year]>2010 + 5
               then 'Expires After 5 Years'
               else 'No Expiration Year Listed' 
end
from AccessTabF1
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-05-16 07:01:38

在您的例子中,您不需要嵌套多个case表达式。

代码语言:javascript
复制
SELECT AccessTabF1.Month, AccessTabF1.Year, AccessTabF1.[Entity Number], 
case when [Exp Year] = 2010 + 1 -- why not = 2011 ?
     then 'Expires in 1 to 5 Years' -- this does not match the logic on line above
     when [Exp Year] > 2010 + 5 -- why not > 2015 ?
     then 'Expires After 5 Years'
     else 'No Expiration Year Listed' 
end
from AccessTabF1
票数 12
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10609972

复制
相关文章

相似问题

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