在一条sql语句中更新多行中的多列?

发布于 2024-09-16 09:58:07 字数 358 浏览 10 评论 0原文

这个伪代码(不准确的 SQL)显示了我想要做的事情。

update tableA (colA, colB, colC, colD)
select b.colA, b.colB, c.colC, c.colD
from tableB b 
    left outer join tableC c 
       on b.id = c.id
    inner join tableA a 
       on c.myNum = a.myNum 
    inner join tableD 
        on a.newId = f.newId
where f.imported = 1

我怎样才能以语法正确的方式做到这一点?

This pseudocode (inaccurate SQL) shows what I want to do.

update tableA (colA, colB, colC, colD)
select b.colA, b.colB, c.colC, c.colD
from tableB b 
    left outer join tableC c 
       on b.id = c.id
    inner join tableA a 
       on c.myNum = a.myNum 
    inner join tableD 
        on a.newId = f.newId
where f.imported = 1

How can I do this in a syntactically correct fashion?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

生活了然无味 2024-09-23 09:58:07

像这样的事情:

UPDATE TABLE 
SET ...
FROM Table1, Table2 ....
WHERE .....


update tableA 
 Set a.ColA = b.ColA,
     a.Colb = b.ColB,
     a.ColC = c.Colc,
     a.ColD = c.ColD
from tableB b 
 left outer join tableC c 
   on b.id = c.id
 inner join tableA a 
   on c.myNum = a.myNum 
 inner join tableD 
    on a.newId = f.newId
 where f.imported = 1

Something like this:

UPDATE TABLE 
SET ...
FROM Table1, Table2 ....
WHERE .....


update tableA 
 Set a.ColA = b.ColA,
     a.Colb = b.ColB,
     a.ColC = c.Colc,
     a.ColD = c.ColD
from tableB b 
 left outer join tableC c 
   on b.id = c.id
 inner join tableA a 
   on c.myNum = a.myNum 
 inner join tableD 
    on a.newId = f.newId
 where f.imported = 1
忘羡 2024-09-23 09:58:07
SQL> select *from Dewashish84;

E_ID E_NAME        E_EDUCATION
---------- ------------- ---------------

   100 dewa          MCA
   101 Raj           MSCIT
   145 mohan         BA
   103 ram           MTECH
     5 Sohan         BTECH

SQL>

update harshad set E_NAME= decode(E_EDUCATION,'MCA','dewa','MSCIT','Raj','BA','mohan',
     'MTECH','ram');

 5 rows updated.
SQL> select *from Dewashish84;

E_ID E_NAME        E_EDUCATION
---------- ------------- ---------------

   100 dewa          MCA
   101 Raj           MSCIT
   145 mohan         BA
   103 ram           MTECH
     5 Sohan         BTECH

SQL>

update harshad set E_NAME= decode(E_EDUCATION,'MCA','dewa','MSCIT','Raj','BA','mohan',
     'MTECH','ram');

 5 rows updated.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文