
- 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
MySQL SUM function to add decimal values
Let us first create a table −
mysql> create table DemoTable ( Money DECIMAL(7,2) ); Query OK, 0 rows affected (0.58 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(100.67); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(199.33); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(500); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(400); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(800); Query OK, 1 row affected (0.14 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+--------+ | Money | +--------+ | 100.67 | | 199.33 | | 500.00 | | 400.00 | | 800.00 | +--------+ 5 rows in set (0.00 sec)
Following is the query to add decimal values/ −
mysql> select sum(Money) from DemoTable;
This will produce the following output −
+------------+ | sum(Money) | +------------+ | 2000.00 | +------------+ 1 row in set (0.00 sec)
- Related Articles
- How to add column values in MySQL without using aggregate function?
- How to add +1 to existing MySQL values?
- How MySQL SUM() function evaluates if the column having NULL values too?
- How can we use MySQL SUM() function to calculate the sum of only dissimilar values of the column?
- How to add some days to str_to_date() MySQL function?
- Floor the decimal values in MySQL instead of round?
- How do I get SUM function in MySQL to return '0' if no values are found?
- Map function and Dictionary in Python to sum ASCII values
- How can MySQL COALESCE() function be used with MySQL SUM() function to customize the output?
- Add to existing value in MySQL column using CONCAT function?
- Remove decimal from records and sum them using a MySQL query
- Sum columns corresponding values according to similar dates in MySQL?
- How to add columns values with suffixed currency sign in MySQL
- How to add duplicate varchar values without displaying error in MySQL?
- Effective way to add integers based on table values in MySQL?

Advertisements