Sunday, April 18, 2010

COUNT() function

0 comments
 The COUNT() function returns the number of rows that matches a specified criteria.
(NULL values will not be counted) of the specified column:
Count()
SQL Syntax
1. SQL COUNT(column_name) Syntax
SELECT COUNT(Customer) AS CustomerNilsen
FROM Orders
WHERE Customer='Nilsen'
Count(*)SQL COUNT(*) Syntax

The COUNT(*) function returns the number of records in a table:
2. SELECT COUNT(*) FROM table_name
SELECT COUNT(*) AS NumberOfOrders
FROM Orders
Distinct Count
SQL COUNT(DISTINCT column_name) Syntax
The COUNT(DISTINCT column_name) function returns the number of distinct values of the specified column:
SELECT COUNT(DISTINCT column_name) FROM table_name
SELECT COUNT(DISTINCT Customer) AS NumberOfCustomers
 FROM Orders

0 comments: