
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How MySQL evaluates if I will use an expression within SUM() function?
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)
- Related Articles
- 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?
- 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?
- 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?
- How can we use MySQL SUM() function?
- How MySQL evaluates an empty hexadecimal value?
- How MySQL evaluates if we use EXISTS operator with the subquery that returns NULL?
- How MySQL evaluates if we use EXISTS operator with a subquery that returns no rows?
- How MySQL evaluates if I try to add two numbers that are contained in quotes?
- 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?

Advertisements