Count function
Description
In SQL Server (Transact-SQL), the COUNT function returns the count of an expression.
Syntax
The syntax for the COUNT function in SQL Server (Transact-SQL) is:
SELECT COUNT(aggregate_expression) FROM tables [WHERE conditions];
OR the syntax for the COUNT function when grouping the results by one or more columns is:
SELECT expression1, expression2, ... expression_n,
COUNT(aggregate_expression)
FROM tables
[WHERE conditions]
GROUP BY expression1, expression2, ... expression_n;
Parameters or Arguments
- expression1, expression2, ... expression_n
- Expressions that are not encapsulated within the COUNT function and must be included in the GROUP BY clause at the end of the SQL statement.
- aggregate_expression
- This is the column or expression whose non-null values will be counted.
- tables
- The tables that you wish to retrieve records from. There must be at least one table listed in the FROM clause.
- WHERE conditions
- Optional. These are conditions that must be met for the records to be selected.
- expression1, expression2, ... expression_n
- Expressions that are not encapsulated within the SUM function and must be included in the GROUP BY clause at the end of the SQL statement.
- aggregate_expression
- This is the column or expression that will be summed.
- tables
- The tables that you wish to retrieve records from. There must be at least one table listed in the FROM clause.
- WHERE conditions
- Optional. These are conditions that must be met for the records to be selected.
SUM Function
Syntax
The syntax for the SUM function in SQL Server (Transact-SQL) is:
SELECT SUM(aggregate_expression) FROM tables [WHERE conditions];
OR the syntax for the SUM function when grouping the results by one or more columns is:
SELECT expression1, expression2, ... expression_n,
SUM(aggregate_expression)
FROM tables
[WHERE conditions]
GROUP BY expression1, expression2, ... expression_n;
Comments
Post a Comment