1

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

Mona
  • 273
  • 1
  • 2
  • 13

3 Answers3

1

I think you are looking for:

select floor(quantity / price) as output
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
0

Casting issues?

select cast(quantity / price as bigint)

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

staticor
  • 620
  • 9
  • 19
0

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
leftjoin
  • 36,950
  • 8
  • 57
  • 116