INF: Mix of Aggregate Functions & Column Names w/out GROUP BYID: Q80284
|
When both aggregate functions and table columns are included in the select list of a query without the GROUP BY clause, the WHERE clause applies only to the rows included in the calculation of the aggregate function, but does not restrict the rows returned by the query. Similarly, if a HAVING clause is used without a GROUP BY clause (which is proper in SQL Server), a HAVING clause restricts the rows returned by the query but does not affect the calculation of the aggregate function.
Consider the following query
select count (stor_id), stor_id from stores WHERE stor_id="7066"
stor_id
------ -------
1 7066
1 7067
1 7131
1 8042
1 6380
1 7896
select count (stor_id), stor_id from stores HAVING stor_id="7066"
stor_id
------ -------
6 7066
select count (stor_id), stor_id from stores WHERE stor_id="7066"
HAVING stor_id="7066"
stor_id
------ -------
1 7066
Additional query words: Windows NT dblib
Keywords : kbprg SSrvDB_Lib SSrvGen SSrvTrans SSrvWinNT
Version : 4.2 | 4.2
Platform : OS/2 WINDOWS
Issue type :
Last Reviewed: March 11, 1999