Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
I've this query like:SELECT DISTINCT ...AVG(D_VALUE),... FROM HEADER_DATA,DETAILS_DATA,GUIDE_INFOWHERE ..............................................AND ROUND(AVG(D_VALUE), G_PREC) > ROUND(G_LEVEL, G_PREC)It's giving me error like -'An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause or a select list, and the column being aggregated is an outer reference'I tried to pseudo name the AVG(D__VALUE) in the SELECT, then using it in the WHERE, but it doesn't recognize it.What would be a get around?Thanks.
russell
Pyro-ma-ni-yak
5072 Posts
Posted - 2009-11-06 : 18:01:27
Look at GROUP BY and HAVING in BOL.HAVING is how you filter aggregates. It's similar to a WHERE clause for the aggregation