需要加入SQL Server 2008,我只是迷路了

需要加入SQL Server 2008,我只是迷路了,sql,sql-server-2008,Sql,Sql Server 2008,我从1992年到1999年用SQL编程。我在SQL Server 2008的一份新的培训工作中陷入了困境,因为我已经15年没有编程了 我知道我要做很多事情。你能帮我看看这个吗 两张表: 朗欧大师: 新译本: 我需要将New_translations.status更新为3,如下所示: New-Translations.English=Lang\u Master.Master\u Text……….Text\u ID=X Lang\u Master.County\u ID=166…….Text\u I

我从1992年到1999年用SQL编程。我在SQL Server 2008的一份新的培训工作中陷入了困境,因为我已经15年没有编程了

我知道我要做很多事情。你能帮我看看这个吗

两张表:

朗欧大师:

新译本:

我需要将New_translations.status更新为3,如下所示:

New-Translations.English=Lang\u Master.Master\u Text……….Text\u ID=X Lang\u Master.County\u ID=166…….Text\u ID=X 新的\u翻译。翻译语言\u主控。主控\u文本 基本上,如果主表中有翻译,但与新的_翻译表中的翻译不同,我需要将其标记为“3”

e、 g.所需结果:

新译本:

就我所知:

update new_translations
set status = 3 
where translation in
    (select LM.master_text
    from lang_master as LM
        , new_translations as NT
     where  NT.english <> LM.text_ID
      and LM.country_id = 65  
     and LM.text_ID in 
  ( select LM.text_id 
    from lang_master as LM
         ,new_translations as NT
    where LM.master_text = NT.translation
    and LM.country_id = 166))

我知道这一切都错了,但我就是不知道该怎么办!请帮忙

如果我正确理解了您的问题,您的查询应该如下所示:

UPDATE new_translation n1 SET status = 3 WHERE EXISTS
(
   SELECT m1.text_id, m1.country_id c1, m1.master_text mt1, m2.country_id c2, m2.master_text mt2 
   FROM lang_master m1 INNER JOIN lang_master m2
   ON m1.text_id = m2.text_id and m1.country_id > m2.country_id
   WHERE n1.country_id = m1.country_id AND m1.master_text <> n1.translation 
     AND m2.master_text = n1.english 
);

下面是fiddle的试用版:

我建议您可以基于以下lang_master和new_translations表之间的公共字段进行连接

然后,下面的查询可以提供帮助:

update NT 
set status = 3 
FROM lang_master lm JOIN new_translations nt
ON lm.text_id = nt.text_id
and lm.Country_ID = nt.Country_ID
and lm.master_text <> nt.translation

如果连接列不同,只需更新连接条件即可。但或多或少,以上几行中的某些东西会起作用。

除了国家id外,lang_master与新的翻译之间有什么联系?textID是否也存在于新的_翻译中?上述更新语句的结果是什么?现在新的_翻译看起来像什么?也许,field-felda-166行也应该给我标记状态3?
update new_translations
set status = 3 
where translation in
    (select LM.master_text
    from lang_master as LM
        , new_translations as NT
     where  NT.english <> LM.text_ID
      and LM.country_id = 65  
     and LM.text_ID in 
  ( select LM.text_id 
    from lang_master as LM
         ,new_translations as NT
    where LM.master_text = NT.translation
    and LM.country_id = 166))
UPDATE new_translation n1 SET status = 3 WHERE EXISTS
(
   SELECT m1.text_id, m1.country_id c1, m1.master_text mt1, m2.country_id c2, m2.master_text mt2 
   FROM lang_master m1 INNER JOIN lang_master m2
   ON m1.text_id = m2.text_id and m1.country_id > m2.country_id
   WHERE n1.country_id = m1.country_id AND m1.master_text <> n1.translation 
     AND m2.master_text = n1.english 
);
text_id
Country_id
update NT 
set status = 3 
FROM lang_master lm JOIN new_translations nt
ON lm.text_id = nt.text_id
and lm.Country_ID = nt.Country_ID
and lm.master_text <> nt.translation