Tag archive
Commands grouped around the same concept, pattern, or recurring problem.
Count or sum only the rows that match a specific condition without a WHERE clause — using `FILTER (WHERE ...)` in PostgreSQL and SQLite, or `CASE WHEN` inside the aggregate for other engines.
Use COUNT as a window function to number how many rows have appeared up to the current row.
Return the number of items stored in a JSON array value.
Audit a table for `NULL` values by counting how many rows have no value in each column of interest.
Aggregate a result set into a single row that reports how many rows matched.
Count only the distinct values in a column, ignoring duplicates.
Measure how many unique users completed each stage of a multi-step flow using `COUNT(DISTINCT CASE WHEN event_name = '...' THEN user_id END)` per step.
Group rows by the candidate key and keep only values that appear more than once.
Aggregate rows by category with `GROUP BY` and count how many rows fall into each group.
Use more than one column in `GROUP BY` when each combination defines a separate aggregate bucket.
`COUNT(column)` skips `NULL` values, while `COUNT(*)` counts every row that made it into the result set.