4
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)が必要です

4

3 に答える 3

5

常にこれがあります:

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 
    )
)
于 2011-06-11T22:44:50.723 に答える
0

'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)

テーブルの構造と選択したいものを教えていただければ、適切なクエリを見つけることができます。

于 2011-06-11T20:13:42.990 に答える
0
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の列を1つだけチェックする必要があります。

あなたはこれを書くことができます(それはあなたの目的を満たさないかもしれません):

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
)
于 2019-12-08T06:19:28.990 に答える