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(
总是这样:
select *
from campaigns
where id not in (
select id_campaign from (
select e.id_campaign as id_campaign, d.frequency, e.id
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
)
)
"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)
如果你能告诉我们表的结构和你想选择什么,我们就能为你找到合适的查询。
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....
)
您正在检查不在中的id,因此,您应该只检查一列的检查id。
你可以这样写(它可能无法实现你的目的(:
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
countcap < d.frequency
)