加入时 AND NOT EXISTS 中缺少右括号错误?

Missing Right Parenthesis Error in an AND NOT EXISTS when joining?

有点难过。调用一些 AND NOT EXISTS 和我加入的那个一直给我 "Missing right Parenthesis" 错误并将错误光标发送到 JOIN 中的 J。任何帮助都会很棒!谢谢

AND NOT EXISTS (SELECT 1 FROM gift g 
  WHERE g.gift_donor_id = xc5.id_number
    AND g.gift_associated_amount + g.gift_associated_credit_amt > 0
 JOIN primary_gift pg ON pg.prim_gift_receipt_number = g.gift_receipt_number
                     AND pg.prim_gift_source_of_info = 'AW')

这显然只是您代码的一部分,但我现在可以看到您在第 3 行和第 4 行之间缺少右括号:

AND NOT EXISTS (SELECT 1 FROM gift g 
  WHERE g.gift_donor_id = xc5.id_number
    AND g.gift_associated_amount + g.gift_associated_credit_amt > 0
) -- <== This one was missing.
 JOIN primary_gift pg ON pg.prim_gift_receipt_number = g.gift_receipt_number
                     AND pg.prim_gift_source_of_info = 'AW')

或者你需要像这样重新排列它:

AND NOT EXISTS (
    SELECT 1 FROM gift g 
      JOIN primary_gift pg
        ON pg.prim_gift_receipt_number = g.gift_receipt_number
       AND pg.prim_gift_source_of_info = 'AW'
     WHERE g.gift_donor_id = xc5.id_number
       AND g.gift_associated_amount + g.gift_associated_credit_amt > 0)

以便连接出现在 where 子句之前。