- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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)
Advertisements