操作数应包含1列 - MySQL不在SELECT * from campaigns WHERE id not in(SELECT
e.id_campaign, d.name, d.frequency, d.country, d.referral, d.bid, d.status, COUNT(e.id) AS countcap
FROM campaigns d LEFT JOIN served e ON d.id = e.id_campaign
WHERE
d.status = 'Active'
GROUP BY e.id_campaign HAVING
countcap < d.frequency)我得到错误“操作数应该包含1列” - 但我需要COUNT(e.id)
3 回答
侃侃无极
TA贡献2051条经验 获得超10个赞
'not in'子句需要一个值列表。因此,以下查询将起作用:
SELECT * from campaigns WHERE id not in(SELECT e.id_campaign FROM campaigns d LEFT JOIN served e ON d.id = e.id_campaign WHERE d.status = 'Active' GROUP BY e.id_campaign HAVING COUNT(e.id) < d.frequency)
如果您可以告诉我们表的结构以及您想要选择的内容,我们将能够为您找出正确的查询。
POPMUISE
TA贡献1765条经验 获得超5个赞
这取决于数据库。您通常可以使用LEFT JOIN而不是其他子查询,但HAVING要求会使事情复杂化。我通常只是尝试清楚地表达逻辑并让数据库弄清楚,如果它太慢,那么你看一下数据,索引和查询计划并开始调整。
添加回答
举报
0/150
提交
取消