- Trending Categories
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
MySQL query to calculate the total amount from column values with Cost and Quantity?
Let us first create a table −
mysql> create table DemoTable ( Cost int, Quantity int ); Query OK, 0 rows affected (0.80 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(65,2); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable values(290,4); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(40,3); Query OK, 1 row affected (0.10 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+------+----------+ | Cost | Quantity | +------+----------+ | 65 | 2 | | 290 | 4 | | 40 | 3 | +------+----------+ 3 rows in set (0.00 sec)
Following is the query to calculate the total amount −
mysql> select Cost,Quantity,Cost*Quantity AS Total_Amount from DemoTable;
This will produce the following output −
+------+----------+--------------+ | Cost | Quantity | Total_Amount | +------+----------+--------------+ | 65 | 2 | 130 | | 290 | 4 | 1160 | | 40 | 3 | 120 | +------+----------+--------------+ 3 rows in set (0.02 sec)
- Related Articles
- MySQL query to count all the column values from two columns and exclude NULL values in the total count?
- How to subtract the same amount from all values in a column with MySQL?
- MySQL query to remove special characters from column values?
- MySQL query to calculate sum from 5 tables with a similar column named “UP”?
- MySQL query to find the average of only first three values from a column with five values
- MySQL query to display only the column values with corresponding column having whitespace
- MySQL query to separate and select string values (with hyphen) from one column to different columns
- MySQL query to retrieve only the column values with special characters?
- MySQL query to replace backslash from a varchar column with preceding backslash string values
- MySQL query to remove string from a column with values EMP1, EMP2, EMP3, etc.
- MySQL query to match any of the two strings from column values
- MySQL query to fetch the maximum corresponding value from duplicate column values
- MySQL query to get string from one column and find its position in another column with comma separated values?
- MySQL query to select column values ending with certain character/number?
- MySQL query to increment one of the column values

Advertisements