How to place a thousand separator in MySQL records?


Use the FORMAT() method for this. Let us first create a table −

mysql> create table DemoTable
   -> (
   -> Amount DECIMAL(10,2)
   -> );
Query OK, 0 rows affected (0.45 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable values(84848757.60);
Query OK, 1 row affected (0.14 sec)

mysql> insert into DemoTable values(95868685.50);
Query OK, 1 row affected (0.15 sec)

mysql> insert into DemoTable values(4242342.36);
Query OK, 1 row affected (0.21 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable;

Output

+-------------+
| Amount      |
+-------------+
| 84848757.60 |
| 95868685.50 |
|  4242342.36 |
+-------------+
3 rows in set (0.00 sec)

Following is the query to set separator in MySQL −

mysql> select format(Amount,2) from DemoTable;

Output

+------------------+
| format(Amount,2) |
+------------------+
| 84,848,757.60    |
| 95,868,685.50    |
| 4,242,342.36     |
+------------------+
3 rows in set (0.00 sec)

Updated on: 30-Jul-2019

967 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements