Example 1
Count rows that match a filter
The WHERE clause limits the rows first, then COUNT(*) collapses the remaining set to one numeric result.
Source table data Rows loaded before the example query runs.
Setup
CREATE TABLE tasks (id INT, status VARCHAR(20));
INSERT INTO
tasks (id, status)
VALUES
(1, 'open'),
(2, 'done'),
(3, 'open');Validated query Shared across supported engines.
SQL
SELECT
COUNT(*) AS total_open
FROM
tasks
WHERE
status = 'open';Expected result Returned rows for the shared example.
| total_open |
|---|
| 2 |
All engines return a single-row aggregate result for this example.