

- 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
Format MySQL records (price values) after multiplying them
To format records, use FORMAT(). Let us first create a table −
mysql> create table DemoTable -> ( -> Price decimal(10,4), -> Rate decimal(10,4) -> ); Query OK, 0 rows affected (0.96 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(1000,10.2); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(2000,20.4); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(100,5); Query OK, 1 row affected (0.16 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-----------+---------+ | Price | Rate | +-----------+---------+ | 1000.0000 | 10.2000 | | 2000.0000 | 20.4000 | | 100.0000 | 5.0000 | +-----------+---------+ 3 rows in set (0.00 sec)
Following is the query to format records −
mysql> select format((Price * Rate),2) from DemoTable;
This will produce the following output −
+--------------------------+ | format((Price * Rate),2) | +--------------------------+ | 10,200.00 | | 40,800.00 | | 500.00 | +--------------------------+ 3 rows in set (0.00 sec)
- Related Questions & Answers
- Get price value from span tag and append it inside a div after multiplying with a number in JavaScript?
- Format date while inserting records in MySQL
- Get distinct values and count them in MySQL
- UNIX_TIMESTAMP with date in MySQL query to fetch records after a specific date in different format?
- Display records after a particular date in MySQL
- Remove decimal from records and sum them using a MySQL query
- Find duplicate column values in MySQL and display them
- Find average of corresponding records (Product Price) from duplicate product ids in MYSQL
- Fetch ordered records after a specific limit in MySQL
- Multiplying column with NULL row in MySQL?
- Display USD currency records with the correct format in MySQL
- Why do things become black after burning them?
- Find MongoDB records with Price less than a specific value
- Sum values in MySQL from similar day records
- Update the date and time values while inserting them in MySQL
Advertisements