Page 276 - PYTHON-12
P. 276
For example,
• mysql> Select COUNT(*) from EMPLOYEE;
Output:
+----------------+
| COUNT(*) |
+----------------+
| 5 |
+----------------+
This command, on execution, shall return the total number of records in the table Employee,
which is 5.
• mysql> Select COUNT(DISTINCT City) from EMPLOYEE;
Output:
+-------------------------------+
| COUNT(DISTINCT City) |
+-------------------------------+
| 4 |
+-------------------------------+
This command, on execution, shall return the total number of records on the basis of city with
no duplicate values, i.e., Kanpur is counted only once; the second occurrence is ignored by
MySQL because of the DISTINCT clause. Thus, the output will be 4 instead of 5.
• Aggregate Functions & NULL Values
Consider the following table Employee with NULL values against the Salary field for some
employees:
None of the aggregate functions takes NULL into consideration. NULL values are simply
ignored by all the aggregate functions as clearly shown in the examples given below:
mysql> Select Sum(Salary) from Employee;
Output: 18500
mysql> Select Min(Salary) from Employee;
Output: 4500 (NULL values are not considered.)
mysql> Select Max(Salary) from Employee;
Computer Science with Python–XII 12.46 mysql> Select Avg(Salary) from Employee;
Output: 8000
(NULL values are not ignored.)
mysql> Select Count(Salary) from Employee;
(NULL values are not ignored.)
Output: 3
Output: 6166.66
(It will be calculated as 18500/3, i.e., sum/total no. of records, which
are 3 after ignoring NULL values.)
mysql> Select Count(*) from Employee;
Output: 5