
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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)
Advertisements