- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can we use MySQL SUM() function with HAVING clause?
By using MySQL SUM() function with the HAVING clause, it filters the result based on a specific condition given after the HAVING clause. To understand the above concept, consider an ‘employee_tbl’ table, which is having the following records −
mysql> SELECT * FROM employee_tbl; +------+------+------------+--------------------+ | id | name | work_date | daily_typing_pages | +------+------+------------+--------------------+ | 1 | John | 2007-01-24 | 250 | | 2 | Ram | 2007-05-27 | 220 | | 3 | Jack | 2007-05-06 | 170 | | 3 | Jack | 2007-04-06 | 100 | | 4 | Jill | 2007-04-06 | 220 | | 5 | Zara | 2007-06-06 | 300 | | 5 | Zara | 2007-02-06 | 350 | +------+------+------------+--------------------+ 7 rows in set (0.00 sec)
Now, the query below will use the HAVING clause with SUM() function to get the total of daily_typing_pages which are more than 250.
mysql> Select Name, SUM(daily_typing_pages) From employee_tbl GROUP BY NAME HAVING SUM(daily_typing_pages) > 250; +------+-------------------------+ | name | SUM(daily_typing_pages) | +------+-------------------------+ | Jack | 270 | | Zara | 650 | +------+-------------------------+ 2 rows in set (0.17 sec)
- Related Articles
- How can we use ASCII() function with MySQL WHERE clause?
- How can we use CHAR_LENGTH() function with MySQL WHERE clause?
- How can we use BIN() function with MySQL WHERE clause?
- How can we use FIND_IN_SET() function with MySQL WHERE clause?
- How can we use MySQL INSTR() function with WHERE clause?
- How can we use MySQL SUM() function?
- Can we use the result of a SUM() function in MySQL WHERE clause
- How Can we use MySQL DISTINCT clause with WHERE and LIMIT clause?
- How can we use MySQL REVERSE() function on column’s data along with WHERE clause?
- How can we use a MySQL subquery with FROM clause?
- How can we use two columns with MySQL WHERE clause?
- How can I use SPACE() function with MySQL WHERE clause?
- How can we use WHERE clause with MySQL INSERT INTO command?
- How can we simulate the MySQL INTERSECT query having WHERE clause?
- How can we use MySQL SELECT without FROM clause?

Advertisements