如何在 Hive 中提取小数的一部分

How to extract a part of a decimal in Hive

我有两列,名为 数量价格。数量除以价格。如果结果包含 decimal,我想要 before the decimal。否则,就是这个数字。

我想你在找:

select floor(quantity / price) as output

选角问题?

select cast(数量/价格为 bigint)

顺便说一句,我想你可能想要这个: Hive Data Types Manual

也可以使用 DIV 运算符(对于整数参数):

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

 select quantity div price
   from your_data d 
 ;

结果:

6
4
116