這裏是我的查詢不起作用,因爲它顯然違反了HAVING子句的規則:如何過濾合併列的值的分組查詢?
SELECT
COALESCE(Publisher.name, Affiliate.name) AS Publisher
,dbo.SumKeys(Item.id) AS ItemIDs
FROM
Item
INNER JOIN ItemAccountingStatus ON Item.item_accounting_status_id = ItemAccountingStatus.id
INNER JOIN Affiliate ON Item.affid = Affiliate.affid
INNER JOIN Currency AffiliateCurrency ON Affiliate.currency_id = AffiliateCurrency.id
INNER JOIN Campaign ON Item.pid = Campaign.pid
INNER JOIN CampaignStatus ON Campaign.campaign_status_id = CampaignStatus.id
LEFT OUTER JOIN Publisher ON Affiliate.affid = Publisher.affid
GROUP BY
COALESCE(Publisher.name, Affiliate.name)
,ItemAccountingStatus.name
,CampaignStatus.name
HAVING (
ItemAccountingStatus.name='default'
and CampaignStatus.name='Verified'
and Publisher='AdsMain LLC' -- THIS BREAKS THE QUERY
)
問:有沒有辦法做到這一點?
回答我自己的問題 - 身價離開這個向上或我應該刪除嗎? – 2011-05-05 04:32:08
我會放棄它 - 如果有人遇到同樣的問題,他們可能會很高興找到答案! – 2011-05-05 04:52:17
@marc_s:答案已添加。這是「爲什麼我不能在WHERE子句中訪問我的列別名」的變體「 – gbn 2011-05-05 04:59:04