如何在同一表的角色之间交换值

时间:2019-05-15 12:08:52

标签: sql oracle

让我说我有桌子:

ID    ROLE    NAME    TITLE
--    ----    ----    -----
10    DEF     John    Manager
11    UPD     Sam     Engineer
12    DEF     Jill    Lead
13    UPD     Ray     Engneer

我需要交换值并获取结果:

ID    ROLE    NAME    TITLE
--    ----    ----    -----
10    DEF     Sam     Engineer
11    UPD     John    Manager
12    DEF     Ray     Engineer
13    UPD     Jill    Lead

如何使用Oracle 11g做到这一点 谢谢。

1 个答案:

答案 0 :(得分:-1)

UPDATE the_table dst
FROM the_table src
SET dst.name = src.name
        , dst.title = src.title
WHERE dst.id IN (10,11)
AND src.id IN (10,11)
AND src.id <> dst.id
        ;