我有一个子查询as clicks
的查询
我想做where clicks > 0
,但是我收到一个错误,这不是一个可识别的列。
SELECT top 10 *, (select count(*) FROM po_events aeclk WITH(NOLOCK) where (aeclk.[source] = ae.[source]) as clicks
FROM archived_events ae with(NOLOCK)
where clicks > 0
答案 0 :(得分:1)
虽然我同意这可能是重复的评论,但我还想指出相关的子查询可能效率低下;一石二鸟,你可以这样做:
SELECT TOP 10
ae.*
, aeclk.clicks
FROM archived_events ae
JOIN ( SELECT source
, COUNT(*) AS clicks
FROM po_events
GROUP BY source
) aeclk ON aeclk.[source] = ae.[source]
WHERE clicks > 0