gpt4 book ai didi

sql - 使用 LEFT JOIN 删除

转载 作者:行者123 更新时间:2023-11-29 11:08:48 49 4
gpt4 key购买 nike

我想根据引用第一个表的另一个表中存在的数据从表中删除,但是,当我将它作为 SELECT 语句运行时,我有有效的代码并显示要删除的值,但是当我将其更改为 DELETE 它给我错误,我不明白为什么它们在那里。

DELETE leadCustomer.* FROM coursework.leadCustomer LEFT JOIN coursework.flightBooking
ON leadCustomer.customerID = flightBooking.customerID
WHERE leadCustomer.customerID NOT IN (
SELECT customerID FROM (SELECT customerID, status FROM coursework.flightBooking) AS
StatusCount where status IN ('R','H') GROUP BY customerID
)
AND leadCustomer.customerID = 8;

错误:

ERROR:  syntax error at or near "leadCustomer"
LINE 1: DELETE leadCustomer.* FROM coursework.leadCustomer LEFT JOIN...
^

********** Error **********

ERROR: syntax error at or near "leadCustomer"
SQL state: 42601
Character: 8

我正在使用 postgres

最佳答案

样本。如果表“H”中没有记录,请删除表“A”中的记录

DELETE A FROM ARTICULO_ALMACEN A
LEFT JOIN HISTORICO_UNION H
ON A.COD_ARTICULO = H.COD_ARTICULO
AND A.COD_ALMACEN = H.COD_ARTICULO_ALMACEN
AND A.TPROPIEDAD1 = H.PROPIEDAD1
AND A.TPROPIEDAD2 = H.PROPIEDAD2
AND A.TPROPIEDAD3 = H.PROPIEDAD3
WHERE H.COD_ARTICULO IS NULL

关于sql - 使用 LEFT JOIN 删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15521954/

49 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com