我想在同一代码中运行两个查询,但我不知道如何运行。这两个问题如下:

UPDATE usercomp
         SET shiftstart = shifts.shiftstarttime,
             shiftfinish = shifts.shiftfinishtime
FROM shifts
     WHERE usercomp.shiftid = shifts.id
         SET break1start = breaks.timestarted,
             break1finish = breaks.timefinished,
             break1duration = breaks.duration
FROM breaks
     WHERE usercomp.break1id = breaks.id;

我得到以下错误:
ERROR:  syntax error at or near "SET"
LINE 6: SET break1start = breaks.timestarted,

有人能帮忙吗?

最佳答案

你需要写两个UPDATE语句

UPDATE usercomp
    SET shiftstart = shifts.shiftstarttime,
        shiftfinish = shifts.shiftfinishtime
FROM shifts
WHERE usercomp.shiftid = shifts.id;

UPDATE usercomp
    SET break1start = breaks.timestarted,
        break1finish = breaks.timefinished,
        break1duration = breaks.duration
FROM breaks
WHERE usercomp.break1id = breaks.id;

关于sql - 创建一个多重查询,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50934052/

10-15 18:24