在opertor与案件 [英] in opertor with case

查看:89
本文介绍了在opertor与案件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以在case语句中使用这个逻辑比较两个表列记录



can we compare two table columns records using this logic in case statement

update Table1 set Description=
(
case
when (select Column1 from Table1 where Column1 IN (select Column2 from Table2) )  then 'data is match'
else 'Data is not match'  end
)

推荐答案

如果这是SQL S我会使用LEFT OUTER JOIN代替。子查询,尤其是子查询中的 IN 执行得非常差,并且在JOIN执行操作时不应使用。



If this is SQL Server, I'd use a LEFT OUTER JOIN instead. Subqueries and especially IN on subqueries perform very poorly and should not be used when a JOIN will do the trick.

UPDATE #Table1 
SET [Description]=
  CASE 
    WHEN #Table2.[Column1] IS NOT NULL THEN 'data is match'
    ELSE 'Data is not match'
    END
FROM #Table1 
LEFT OUTER JOIN #Table2
ON #Table1.[Column1]=#Table2.[Column1]


你应该能够做使用EXISTS:

You should be able to do that using EXISTS:
update Table1 set Description=
(
case
when exists(select * from Table1 where Column1 IN (select Column2 from Table2) ) then 'data is match'
else 'Data is not match' end
)


这篇关于在opertor与案件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆