具有条件的SQL Server查询具有与Excel VLookup相同的功能

用户名
select 
b.columnb,
case when a.columna is null then 'FALSE' else 'TRUE' end 
from
tableb b left outer join
tablea a on b.columnb = a.columna 

在上面的查询中,我怎么能再包含一个条件以仅查看“ False”值?

谢谢。

hu

只需添加WHERE到您的SELECT声明中:

select 
b.columnb,
case when a.columna is null then 'FALSE' else 'TRUE' end 
from
 tableb b 
 left outer join tablea a on (b.columnb = a.columna)
WHERE a.columna IS NULL;

在这种情况下,您可以将其简化为:

SELECT
b.columnb,
'FALSE'
FROM
 tableb b 
 LEFT OUTER JOIN tablea a ON (b.columnb = a.columna)
WHERE a.columna IS NULL;

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章