Finding the sum of integers from multiple MySQL rows in same column?


Let us first create a table −

mysql> create table DemoTable739 (Price int);
Query OK, 0 rows affected (0.65 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable739 values(100);
Query OK, 1 row affected (0.15 sec)
mysql> insert into DemoTable739 values(50);
Query OK, 1 row affected (0.14 sec)
mysql> insert into DemoTable739 values(1200);
Query OK, 1 row affected (0.19 sec)
mysql> insert into DemoTable739 values(500);
Query OK, 1 row affected (0.37 sec)
mysql> insert into DemoTable739 values(800);
Query OK, 1 row affected (0.20 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable739;

This will produce the following output -

+-------+
| Price |
+-------+
| 100   |
| 50    |
| 1200  |
| 500   |
| 800   |
+-------+
5 rows in set (0.00 sec)

Following is the query to find the sum of integers from multiple MySQL rows in same column −

mysql> select sum(Price) as Total_Price from DemoTable739;

This will produce the following output -

+-------------+
| Total_Price |
+-------------+
| 2650        |
+-------------+
1 row in set (0.00 sec)

Updated on: 22-Aug-2019

145 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements