- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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 MySQL evaluates if I will use an expression within SUM() function?
152 Lectures 16 hours
87 Lectures 5.5 hours
When we include an expression within SUM() function then MySQL evaluates it for each row of data and the total result is returned. To understand it, consider the following example of table ‘employee’, having the following details −
mysql> Select * from Employee; +----+--------+--------+ | ID | Name | Salary | +----+--------+--------+ | 1 | Gaurav | 50000 | | 2 | Rahul | 20000 | | 3 | Advik | 25000 | | 4 | Aarav | 65000 | | 5 | Ram | 20000 | | 6 | Mohan | 30000 | | 7 | Aryan | NULL | | 8 | Vinay | NULL | +----+--------+--------+ 8 rows in set (0.00 sec)
Now, suppose if we want to know the total salary of the employees from the above table after deducting 1000 rupees from each employee’s salary then we can calculate it by using an expression within SUM() function, Following query will produce the required result set −
mysql> Select SUM(Salary-1000) from Employee; +------------------+ | SUM(Salary-1000) | +------------------+ | 204000 | +------------------+ 1 row in set (0.05 sec)
- How MySQL evaluates when I use a conditional expression within SUM() function?
- How can I use MySQL IF() function within SELECT statement?
- How MySQL SUM() function evaluates if the column having NULL values too?
- What happens if I will use integer values as arguments of MySQL LOCATE() function?
- Can I use SUM() with IF() in MySQL?
- How can I use a SELECT statement as an argument of MySQL IF() function?
- What MySQL ASCII() function returns if I will provide NULL to it?
- What will MySQL CHAR_LENGTH() function return if I provide NULL to it?
- How MySQL SUM() function evaluates if it got the column, having character data type, as its argument?
- How MySQL SUM() function evaluates if it is used with SELECT statement that returns no matching rows?
- How MySQL evaluates an empty hexadecimal value?
- How can we use MySQL SUM() function?
- How MySQL evaluates if we use EXISTS operator with the subquery that returns NULL?
- How MySQL behaves if I use INTERVAL keyword with an invalid date?
- How MySQL evaluates if I try to add two numbers that are contained in quotes?