Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQlite large number separate by commas

I am trying to find a way to format any large number 1000 or more with commas in SQlite. So, 1000 would be 1,000. 1000000 would be 1,000,000, and so on.

I can easily handle individual cases by changing the numbers to text and then using SUBSTR, but I need a catch all solution that can be done in SQLite.

Any help is appreciated.

like image 936
HelpWithR Avatar asked Sep 06 '25 15:09

HelpWithR


1 Answers

You can do it with the function printf():

SELECT printf("%,d", col) 
FROM tablename

Replace tablename and col with your table's and the column's name.

See the demo.

like image 76
forpas Avatar answered Sep 08 '25 19:09

forpas