- 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 select to convert numbers to millions and billions format?
You can use FORMAT() from MySQL to convert numbers to millions and billions format. Let us first create a table−
mysql> create table DemoTable ( Value BIGINT ); Query OK, 0 rows affected (0.74 sec)
Insert records in the table using insert command −
mysql> insert into DemoTable values(78000000000); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(10000000000); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(90000000000); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(450600000000); Query OK, 1 row affected (0.41 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+--------------+ | Value | +--------------+ | 78000000000 | | 10000000000 | | 90000000000 | | 450600000000 | +--------------+ 4 rows in set (0.00 sec)
Following is the query to convert numbers to million and billions format−
mysql> select format(Value,0) as `FormatValue` from DemoTable;
This will produce the following output−
+-----------------+ | FormatValue | +-----------------+ | 78,000,000,000 | | 10,000,000,000 | | 90,000,000,000 | | 450,600,000,000 | +-----------------+ 4 rows in set (0.00 sec)
Advertisements