Mona
Mona

Reputation: 311

How to extract a part of a decimal in Hive

I have two columns called quantity and price. Quantity is divided by price. If the result contains decimal, I want the number before the decimal. Or else, the number as it is.

enter image description here

Upvotes: 1

Views: 1400

Answers (3)

leftjoin
leftjoin

Reputation: 38335

Also DIV operator can be used (for integer arguments):

 with your_data as (
    select stack(3, 13,2,8,2,233,2) as(quantity,price)
    )

 select quantity div price
   from your_data d 
 ;

Result:

6
4
116

Upvotes: 0

staticor
staticor

Reputation: 618

Casting issues?

select cast(quantity / price as bigint)

By the way, I think you may want this: Hive Data Types Manual

Upvotes: 0

Gordon Linoff
Gordon Linoff

Reputation: 1270021

I think you are looking for:

select floor(quantity / price) as output

Upvotes: 1

Related Questions