Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to format int number output with thousand separator in hive sql

Tags:

hive

Do you know how to format the output of a number in hive with thousand separator? For example:

data:146452664

output:146,452,664

I use this in Teradata, but don't know how to achieve in Hive.

cast(cast(cast(number as integer) as format'ZZZ,ZZZ,ZZZ,ZZ9') as char(11)) 
like image 930
Kiki Du Avatar asked Mar 28 '18 06:03

Kiki Du


People also ask

How do I add a thousand separator in SQL?

The convert function can put the thousands separator in for you, but only if you are converting from the Money data type to the varchar data type. You also need to use the optional 3rd parameter of the convert function.

How do I cast currency in SQL?

In SQL Server, you can use the T-SQL FORMAT() function to format a number as a currency. The FORMAT() function allows you to format numbers, dates, currencies, etc. It accepts three arguments; the number, the format, and an optional “culture” argument.


1 Answers

Use the format_number() function.

select format_number(146452664,0)

The first argument is the number and second is the number of decimal places to round.If D is 0, the result has no decimal point.

like image 80
Kaushik Nayak Avatar answered Sep 21 '22 11:09

Kaushik Nayak