
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- 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
- Get the sum of last 3 digits from all the values in a column with MySQL
- MySQL query to group by column and display the sum of similar values in another column
- Find the sum of a column values based on another numerical column in R.
- Get the sum of a column in all MySQL rows?
- How MySQL SUM() function evaluates if the column having NULL values too?
- Display the sum of positive and negative values from a column in separate columns with MySQL
- Match column values on the basis of the other two column values in MySQL
- SUM a column based on a condition in MySQL
- Add a temporary column in MySQL where the values depend on another column?
- Sum values of a single row in MySQL?
- Sum the score of duplicate column values in MongoDB documents?
- How to find the sum of a column values up to a value in another column in R?
- Setting column values as column names in the MySQL query result?
Advertisements