0% found this document useful (0 votes)
4 views1 page

MySQL COUNT() Function Examples

The document provides examples of using the MySQL COUNT() function with a sample 'employees' table. It includes queries to count all rows, non-NULL salaries, employees in specific departments, and distinct departments, as well as using GROUP BY and HAVING clauses. These examples illustrate how to aggregate and filter data in SQL effectively.

Uploaded by

narendramehtaa
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

MySQL COUNT() Function Examples

The document provides examples of using the MySQL COUNT() function with a sample 'employees' table. It includes queries to count all rows, non-NULL salaries, employees in specific departments, and distinct departments, as well as using GROUP BY and HAVING clauses. These examples illustrate how to aggregate and filter data in SQL effectively.

Uploaded by

narendramehtaa
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

MySQL COUNT() Examples Sample Table: employees id | name | department | salary

1 | Rohan | HR | 30000
2 | Priya | IT | 45000
3 | Aarav | IT | 50000
4 | Simran | Finance | NULL
5 | Krish | HR | 28000
1. Count all rows SELECT COUNT(*) FROM employees; 2. Count non-NULL salary SELECT
COUNT(salary) FROM employees; 3. Count employees in IT SELECT COUNT(*) FROM
employees WHERE department = 'IT'; 4. Count employees per department (GROUP BY) SELECT
department, COUNT(*) AS total FROM employees GROUP BY department; 5. Count departments
with more than 1 employee (HAVING) SELECT department, COUNT(*) AS total FROM employees
GROUP BY department HAVING COUNT(*) > 1; 6. Count distinct departments SELECT
COUNT(DISTINCT department) FROM employees;

You might also like