[英]case when in sql
I have table when contains who's two column contains data/null , i want to capture only rows which is not null. 当包含谁的两列包含data / null时我有表,我只想捕获不为null的行。
example of t1 t1的例子
Application_channel | reason_for_joining
call | null
null | do not wish to provide
null | null
I want output as 我想输出为
Status
call
do not wish to provide
query i wrote is somthing like:- 我写的查询有点像:
select case
when reason_for_joining is null and application_channel is not null then application_channel
when application_channel is null and reason_for_joining is not null then
reason_for_joining else application_channel end as status
from t1
the problem is its also taking null when both the column has null value which i dont want. 问题是当两个列都具有我不想要的空值时,它也取空值。 Any help much appreciated.
任何帮助,不胜感激。
He also wanted to filter those that are empty, so it would be: 他还想过滤那些空的,所以它将是:
select coalesce(Application_channel, reason_for_joining) as status
from t1
where coalesce(Application_channel, reason_for_joining) is not null
Alternatively you could also filter like this: 另外,您也可以这样过滤:
WHERE Application_channel IS NOT NULL OR reason_for_joining IS NOT NULL
You want coalesce()
: 您想要
coalesce()
:
select coalesce(Application_channel, reason_for_joining) as status
from t1
Is case of two parameter ISNULL also do same work 是两个参数ISNULL的情况也做同样的工作
select ISNULL('call',null),isnull(null,'do not')
so in you query 所以在你查询
select ISNULL(Application_channel, reason_for_joining) as status
from t1
where ISNULL(Application_channel, reason_for_joining) is not null
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.