SQLite 3 reference · Aggregate Functions
SQLite COUNT() Function
Count rows: count(*) counts every row, count(X) counts rows where X isn't NULL, count(DISTINCT X) counts unique values.
SQLite 3
Syntax
count(*) | count(X) | count(DISTINCT X)
Parameters
| Parameter | Description |
|---|---|
X |
A column or expression. |
Return value
An integer.
Examples
SELECT count(*) AS customers, count(email) AS with_email, count(DISTINCT country) AS countries
FROM customers;
Output
customers | with_email | countries 10 | 9 | 5
SELECT status, count(*) AS orders
FROM orders
GROUP BY status
ORDER BY orders DESC;
Output
status | orders delivered | 7 shipped | 2 pending | 2 cancelled | 1
In other languages
COUNT()· PostgreSQL
Related
SUM()· Add up the non-NULL values in a group. Returns NULL when there are no values; total() returns 0.0 instead.AVG()· Return the average of the non-NULL values in a group, always as a real number. NULLs are ignored, not counted as 0.TOTAL()· Add up the non-NULL values in a group like sum(), but always return a real number and 0.0 for no rows.- SQL Aggregate Functions · tutorial
- SQL GROUP BY · tutorial