SQL > SQL Functions > Count

Another arithmetic function is COUNT. This allows us to COUNT up the number of row in a certain table. The syntax is,

SELECT COUNT("column_name")
FROM "table_name";

For example, if we want to find the number of store entries in our table,

Table Store_Information

Store_NameSalesTxn_Date
Los Angeles1500Jan-05-1999
San Diego250Jan-07-1999
Los Angeles300Jan-08-1999
Boston700Jan-08-1999

we'd key in,

SELECT COUNT (Store_Name)
FROM Store_Information;

Result:

COUNT (Store_Name)
4

COUNT and DISTINCT can be used together in a statement to retrieve the number of distinct entries in a table. For example, if we want to find out the number of distinct stores, we'd type,

SELECT COUNT (DISTINCT Store_Name)
FROM Store_Information;

Result:

COUNT (DISTINCT Store_Name)
3

Next: SQL MAX




Copyright © 2014   1keydata.com   All Rights Reserved.     Privacy Policy