Database Reference
In-Depth Information
Input
SELECT COUNT(*) AS num_cust
FROM customers;
Output
+----------+
| num_cust |
+----------+
| 5 |
+----------+
Analysis
In this example, COUNT(*) is used to count all rows, regardless of values. The
count is returned in num_cust .
The following example counts just the customers with an e-mail address:
Input
SELECT COUNT(cust_email) AS num_cust
FROM customers;
Output
+----------+
| num_cust |
+----------+
| 3 |
+----------+
Analysis
This SELECT statement uses COUNT(cust_email) to count only rows with a value
in the cust_email column. In this example, cust_email is 3 (meaning that only
three of the five customers have e-mail addresses).
Note
NULL Values Column rows with NULL values in them are ignored by the COUNT()
function if a column name is specified, but not if the asterisk ( * ) is used.
The MAX() Function
MAX() returns the highest value in a specified column. MAX() requires that the
column name be specified, as seen here:
 
 
Search WWH ::




Custom Search