
- 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
Sum the values in a column in MySQL?
For this, use the aggregate function SUM(). Let us first create a table −
mysql> create table DemoTable -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> € int -> ); Query OK, 0 rows affected (0.71 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(€) values(10); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(€) values(200); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(€) values(190); Query OK, 1 row affected (0.14 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
+----+------+ | Id | € | +----+------+ | 1 | 10 | | 2 | 200 | | 3 | 190 | +----+------+ 3 rows in set (0.00 sec)
Following is the query to get the sum in MySQL −
mysql> select sum(€) AS Total from DemoTable;
output
+-------+ | Total | +-------+ | 400 | +-------+ 1 row in set (0.00 sec)
- Related Articles
- Sum up values in a single MySQL column in a specific way?
- Fetch the size of a specific column values in MySQL and display the sum
- MySQL query to group by column and display the sum of similar values in another column
- Get the sum of last 3 digits from all the values in a column with MySQL
- Display the sum of positive and negative values from a column in separate columns with MySQL
- Find the sum of a column values based on another numerical column in R.
- Match column values on the basis of the other two column values in MySQL
- How MySQL SUM() function evaluates if the column having NULL values too?
- How to sum selected column values based on specific month records in MySQL?
- Get the sum of a column in all MySQL rows?
- Add a temporary column in MySQL where the values depend on another column?
- SUM a column based on a condition in MySQL
- Swapping two column values in MySQL?
- Sum values of a single row in MySQL?
- Setting column values as column names in the MySQL query result?

Advertisements