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)

Updated on: 30-Jul-2019

927 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements