where exists (select 1 from text b where a.字段名 = b.字段名) 这个 where 条件的意义是什么?

问答 ev7mtc3 ⋅ 于 2021-03-26 18:18:22 ⋅ 最后回复由 透心凉 2021-03-26 19:27:04 ⋅ 1344 阅读
unit_cost是非空字段
update costs_20210326  t1 
set t1.unit_cost=(select 
case when p.promo_category='TV' then unit_cost+1 
when p.promo_category='NO PROMOTION' then 0 end
from promotions p
where t1.promo_id=p.promo_id 
and t1.time_id=last_day(time_id)
and p.promo_category in ('TV','NO PROMOTION'))

最开始写写的语句不加上 这个where 条件无法更新数据 报错 unit_cost 为空
加上上述where条件之后就可以更新字段了 这是为什么?
where 条件:
where exists (select 1 from text b where a.字段名 = b.字段名)

成为第一个点赞的人吧 :bowtie:
回复数量: 1
  • 透心凉
    2021-03-26 19:27:04

    这个前面要是select * from a的话,后面接你的这个where exists 条件意思就是从a表找出与b表有相同字段的所有结果集;
    然后这个update不加条件,SQL语句不知道怎么更新,加了就相当于返回一个true

暂无评论~~
  • 请注意单词拼写,以及中英文排版,参考此页
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`, 更多语法请见这里 Markdown 语法
  • 支持表情,可用Emoji的自动补全, 在输入的时候只需要 ":" 就可以自动提示了 :metal: :point_right: 表情列表 :star: :sparkles:
  • 上传图片, 支持拖拽和剪切板黏贴上传, 格式限制 - jpg, png, gif,教程
  • 发布框支持本地存储功能,会在内容变更时保存,「提交」按钮点击时清空
Ctrl+Enter