簡體   English   中英

如何將以下 SQL 語句轉換為更新語句

[英]How do I convert the following SQL Statement to an Update Statement

如何將以下 SQL 語句轉換為更新語句:

select
    * 
from
    BomStructure BS
where
    Component = '322058-000000'
    and
    exists
    (
        select
            1
        from
            BomStructure
        where
            ParentPart = BS.ParentPart
            and
            Component = '322123-301200'
    );

我想要

update
    BomStructure BS
set
    StructureOffDate = '2019-09-30'
where 
    Component = '322058-000000'
    and
    exists
    (
        select
            1
        from
            BomStructure
        where
            ParentPart = BS.ParentPart
            and
            Component = '322123-301200'
    );

但是我上面的語法不正確。 請協助。

我想你想要:

update bs
      set bs.StructureOffDate = '2019-09-30'
from BomStructure bs
where exists (select 1 
              from BomStructure bs1
              where bs1.ParentPart = bs.ParentPart and bs1.Component = '322123-301200'
             );

您的外部過濾器將僅更新Component = '322123-301200' ,但根據查詢,您看起來想要更新ParentPart ,其中Component = '322123-301200'

看起來您正在尋找的是更新所有組件“322058-000000”的日期,其父部件也具有組件“322123-301200”。 如果是這樣,以下查詢應該可以解決問題:

update BomStructure
set StructureOffDate = '2019-09-30'
where Component='322058-000000' and Parentpart in (select distinct Parentpart from BomStructure where Component = '322123-301200')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM