sql - 具有多个语句的 SQL 案例查询
问题描述
我正在尝试使用案例查询创建一个新列,但我也想在我的其他案例查询中使用它,如下所示,我无法执行下面的查询。请发表你的意见。谢谢
select
case when ccis.id is not null then 'High'
else null
end as category,
case
when category is not NULL then True
else False
end as flag
FROM "view1" as ccis left outer join "view2" as cctm
on ccis.study_name = cctm.study_name
from goes here ---
Join statement goes here ---
解决方案
您不能category
在下一个CASE
表达式中使用。
但是您可以应用与前面相同的逻辑CASE
:
select
case when id is not null then 'High' end as category,
case when id is not null then 'True' else 'False' end as flag
..........................
因为category
不是null
当id
不是null
。
我else null
从第一个CASE
表达式中删除,因为它是不需要的,因为它是在不满足分支null
中的任何条件时返回的默认功能。when
推荐阅读
- compiler-errors - C++ 从“int”到“int*”的无效转换
- loopbackjs - 是否可以在远程挂钩中执行 models.find() ?
- facebook - 如何在生产 Facebook 页面中进行测试,测试数据仅显示给应用程序的测试人员
- c - if 语句中的逻辑运算符
- c - 将字符串数组添加到c中的字符指针
- html - 为什么 display:inline-block 对齐不符合预期
- tensorflow - 如何使用 tensorflow 1.14 为 keras 层定义自定义渐变
- excel - How to detect 3 consecutive empty rows in excel
- javascript - 注册 ServiceWorker 时如何修复 404 错误?
- r - 当在 for 循环中以编程方式调用块时,Knitr 不打印 ggplots