As mentioned on the previous page,COUNT is one of the functions. Because of its wide use, we have made a special offer here to discuss it. Basically,Count allows us to count how many of the data in the table is selected. Its syntax is:
Select COUNT ("Field name")
From "table name";
For example, if we want to find out how many of the Store_name columns in our demo table are not blank data,
store_information Form
Store_name |
Sales |
Txn_date |
Los Angeles |
1500 |
05-jan-1999 |
San Diego |
250 |
07-jan-1999 |
Los Angeles |
300 |
08-jan-1999 |
Boston |
700 |
08-jan-1999 |
We'll break in,
SELECT COUNT (store_name)
From Store_information
WHERE Store_name is not NULL;
Results:
"is not NULL" means "this field is not blank".
COUNT and DISTINCT are often used together in order to find out how many different data are in the table (as to what is actually unimportant). For example, if we were to find out how many different store_name we had in our table, we would break in,
SELECT COUNT (DISTINCT store_name)
from Store_information;
Results:
COUNT (DISTINCT store_name) |
3 |
Linux measured results:
Reprint please specify: Xiao Liu
A concise tutorial of SQL statements for Linux---COUNT