我想在主查询中使用子查询,如下所示:

SELECT distinct(cnt.crid),cu.companyName,m.*,cnt.*,m.submitDate as mSubmitDate
from tbl_mahmoleh m,tbl_customer cu,tbl_cntreserve cnt
where m.cuID=cu.cuID and m.mBLID=cnt.mBLID and m.cuID='12'
      and (cnt.crID IN (SELECT DISTINCT(crID) FROM tbl_paymentcnt))
      and (cnt.crID IN (SELECT pc.crID, SUM( amount ) AS PaySum
                        FROM tbl_paymentcnt pc GROUP BY pc.crID HAVING PaySum < '2000'))
ORDER BY inputDateD


但是我遇到这个错误


  Blockquote#1241-操作数应包含1列

最佳答案

我明白了,IN子句不能与多个字段一起使用,我将查询更改为以下内容,并且问题得到解决。

SELECT DISTINCT(cnt.crid),cu.companyName,m.*,cnt.*,m.submitDate AS mSubmitDate
FROM tbl_mahmoleh m,tbl_customer cu,tbl_cntreserve cnt
WHERE m.cuID=cu.cuID AND m.mBLID = cnt.mBLID AND m.cuID = '12'
AND (cnt.crID IN (SELECT DISTINCT(crID) FROM tbl_paymentcnt))
AND (cnt.crID IN (SELECT pc.crID FROM tbl_paymentcnt pc GROUP BY pc.crID HAVING SUM(amount) < '2500'))
ORDER BY inputDateD

关于php - #1241-操作数应包含1列:为什么?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26526476/

10-14 13:55