Usage of COUNT in SQL
In this article we will see the 'Usage of COUNT in SQL'
COUNT is an aggregate function in SQL Sever. It returns the number of records returned by a select query.
COUNT function works in SQL Server (starting with 2008 to latest version), Azure SQL Database and many other database also.
COUNT always returns an integer (INT) value as result.
Syntax of the COUNT() function: COUNT function works in SQL Server (starting with 2008 to latest version), Azure SQL Database and many other database also.
COUNT always returns an integer (INT) value as result.
Let's learn use of COUNT() function in SQL Server with an example
(Example : How To Count the no. of members in distinct department)
(Example : How To Count the no. of members in distinct department)
COUNT([ALL | DISTINCT ] expression)
ALL : ALL is the default, and COUNT() function will applies to all values.
SELECT COUNT(*) FROM [TABLENAME]
DISTINCT : COUNT() function will return the number of distinct (unique) non null values.
SELECT COUNT( DISTINCT [COLUMNAME] ) FROM [TABLENAME]
EXPRESSION : is an expression of any type. You cannot use a sub query or an aggregate function in the expression.
0 Comments