无法执行查询

时间:2015-08-21 13:10:37

标签: sql

我正在尝试执行SQL查询,但收到“Missing right parenthesis”错误:

((SELECT CUST_ACCT 
  FROM CUSTMASTER 
  WHERE SITE_ID IN (SELECT SITE_ID FROM HOUSEMASTER WHERE FTAX=1)) 
  AND
 (SELECT CUST_ACCT 
  FROM CUSTMASTER 
  WHERE SITE_ID IN (SELECT SITE_ID FROM  HOUSEMASTER WHERE MGT=1)))

我觉得正确检查了括号。请让我知道缺少什么?

4 个答案:

答案 0 :(得分:1)

您似乎试图通过在它们之间添加and运算符来将两个不同查询的结果作为一个查询。这不会奏效。您可以使用union查询,但看起来它可以简化为下面的查询。

也许这就是你真正想要的?

SELECT CUST_ACCT 
FROM CUSTMASTER 
WHERE SITE_ID IN (
    SELECT SITE_ID 
    FROM HOUSEMASTER 
    WHERE FTAX=1 OR MGT=1
)

答案 1 :(得分:0)

我认为必须有UNION:

((SELECT CUST_ACCT 
  FROM CUSTMASTER 
  WHERE SITE_ID IN (SELECT SITE_ID 
                    FROM HOUSEMASTER 
                    WHERE FTAX = 1)) 
  UNION
  (SELECT CUST_ACCT 
   FROM CUSTMASTER 
   WHERE SITE_ID IN (SELECT SITE_ID FROM HOUSEMASTER WHERE MGT=1)))

答案 2 :(得分:0)

 SELECT CUST_ACCT FROM CUSTMASTER WHERE SITE_ID
 IN (SELECT SITE_ID FROM HOUSEMASTER WHERE FTAX=1 or MGT=1)

答案 3 :(得分:0)

我不确切地知道您的描述不详细。

如果您尝试比较select (true and false)

,请尝试此操作

SELECT ((CUST_ACCT来自CUSTMASTER WHERE SITE_ID IN(从HOUSEMASTER中选择SITE_ID,其中FTAX = 1))和(CUST_ACCT来自CUSTMASTER WHERE SITE_ID IN(从HOUSEMASTER中选择SITE_ID,其中MGT = 1) ))