Collections:
Using Group Functions in the SELECT Clause in SQL Server
How To Use Group Functions in the SELECT Clause in SQL Server?
✍: FYIcenter.com
If group functions are used in the SELECT clause, all rows that meet the criteria defined in the WHERE clause will be treated as a single group. The group functions will be apply all rows in that group as a whole. The final output of the SELECT statement is the resulting values of the group functions, not the rows in the group.
Here are two good examples of using group functions :
SELECT COUNT(*), MAX(counts), MIN(created) FROM fyi_links GO COUNT(*) MAX(counts) MIN(created) 7 972 2003-01-01 SELECT COUNT(*), MAX(counts), MIN(created) FROM fyi_links WHERE tag = 'DBA' GO COUNT(*) MAX(counts) MIN(created) 3 972 2005-01-01
In first case, the group contains all the rows in table fyi_links, because is no WHERE clause. In the second case, the group contains only 3 rows because of the WHERE clause tag = 'DBA'.
⇒ Mixing Group Functions with Non-group Selection Fields in SQL Server
⇐ Group Functions in Query Statements in SQL Server
⇑ Using SELECT Statements and GROUP BY Clauses in SQL Server
2016-10-25, 1284🔥, 0💬
Popular Posts:
How To Format DATETIME Values to Strings with the CONVERT() Function in SQL Server Transact-SQL? SQL...
How To Convert Character Strings into Numeric Values in SQL Server Transact-SQL? Sometimes you need ...
How To Select All Columns of All Rows from a Table with a SELECT statement in SQL Server? The simple...
Is PL/SQL Language Case Sensitive in Oracle? PL/SQL language is not case sensitive: Reserved words a...
How To Replace Given Values with NULL using NULLIF() in SQL Server Transact-SQL? Sometime you want t...