在MySQL中执行关系代数除法的SQL查询时出错

时间:2012-01-18 07:01:36

标签: mysql sql relational-algebra

我有3个表(provider,provider_has_product,product): enter image description here

(原文:http://content.screencast.com/users/Maksold/folders/Jing/media/4e6de435-eeac-4602-95e0-2a1b0b4876ad/2012-01-18_0851.png

我尝试使用此代码进行除法运算:

SELECT DISTINCT `provider_has_product`.`provider_id` FROM `provider_has_product` WHERE NOT EXIST
 (SELECT * FROM `product` WHERE NOT EXIST
  (SELECT * FROM `provider_has_product` A1 WHERE 
     A1.`provider_id` = `provider_has_product`.`provider_id` AND
     A1.`product_id` = `product`.`id`))

但它不起作用。它显示:Error Code: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT * FROM产品WHERE NOT EXIST (SELECT * FROM provider_has_p'位于第2行

如何在MySQL上进行除法并纠正此错误。

1 个答案:

答案 0 :(得分:3)

检查拼写错误。我很确定它是EXISTS,而不是EXIST