sql - 在 where in update 中的 case 表达式
问题描述
我有两个表 CopyMoveSources 和 ListItems。CopyMoveSources 有一个名为 TargetExists 的列。
我需要将 TargetExists 设置为 1 或 0,具体取决于文件是否存在于 ListItems 中。而且我必须只检查 TargetExists 为空的这些行,因此我不会在每次运行查询时检查相同的文件。我希望它是某种案例表达式,所有输入都受到赞赏。
select *
from [dbo].[CopyMoveSources]
where source not in (select path from ListItems)
order by JobId asc
解决方案
听起来你想要一个update
:
update CopyMoveSources
set targetexists = (case when exists (select 1 from listitems li where li.path = copymovesources.source)
then 1 else 0
end)
where targetexists is null
推荐阅读
- autodesk-forge - 遵循 Revit 设计自动化教程时收到错误消息
- javascript - 如何在node.js(茉莉花)中触发错误回调
- azure - 当我们进行重定向时,为什么前门会删除授权标头?
- java - Spring 4 Session Cookie 更改字段
- python - 在另一个框架中查找 Dataframe 字段,如果找到则标记它
- javascript - 使用反应js_在下一页上没有路由按钮导航到按钮单击时的全新页面
- php - 获取数据表jquery中两个日期之间的记录
- javascript - VueJS - 将全局变量从数据共享到内部 scss 文件(动态 CSS)
- javascript - TypeError: Falsy value found in plugins - Vue Unit Testing with Jest
- php - php传递函数并将返回值返回给调用函数