0

我有这个查询和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
4

1 回答 1

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
于 2012-11-12T01:36:42.633 回答