Content
COUNT returns the number of rows that match a specified condition. Essential for data analysis and reporting.
Count All Rows
SELECT COUNT(*) FROM customers;
Count Non-NULL Values
SELECT COUNT(email) FROM customers;
Count with Condition
SELECT COUNT(*) FROM orders WHERE status = 'completed';
Count Distinct Values
SELECT COUNT(DISTINCT country) FROM customers;
Count with GROUP BY
SELECT category, COUNT(*) as product_count
FROM products
GROUP BY category;
Count with HAVING
SELECT category, COUNT(*) as cnt
FROM products
GROUP BY category
HAVING COUNT(*) > 5;
Generate COUNT Queries
Ask "how many" questions to AI2sql and get perfect COUNT queries.


