






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







th
MySQL count() function is used to returns the count of an expression. It allows us to count all rows or only some rows of the table that matches a specified condition. It is a type of aggregate function whose return type is BIGINT. This function returns 0 if it does not find any matching rows. We can use the count function in three forms, which are explained below: o Count (*) o Count (expression) o Count (distinct)
Let us discuss each in detail. COUNT(*) Function: This function uses the SELECT statement to returns the count of rows in a result set. The result set contains all Non-Null, Null, and duplicates rows. COUNT(expression) Function: This function returns the result set without containing Null rows as the result of an expression. COUNT(distinct expression) Function: This function returns the count of distinct rows without containing NULL values as the result of the expression. Syntax : The following are the syntax of the COUNT() function:
Example Execute the following statement that returns all rows from the employee table and WHERE clause specifies the rows whose value in the column emp_age is greater than 32:
Output: MySQL Count() Function with GROUP BY Clause We can also use the count() function with the GROUP BY clause that returns the count of the element in each group. For example, the following statement returns the number of employee in each city:
MySQL sum() function example Consider our database has a table named employees, having the following data. Now, we are going to understand this function with various examples:
This example is used to return the result based on the condition specified in the WHERE clause. Execute the following query to calculate the total working hours of employees whose working_hours >= 12.