【发布时间】:2021-04-17 12:56:11
【问题描述】:
我有 6 列命名为 TOTAL_STOCK_VALUE,VALUE_UNRESTRICTED,fiscal_year,fiscal_period,plant,storage_location。我想从 TOTAL_STOCK_VALUE,VALUE_UNRESTRICTED 列中创建一个百分比增加值的新列。
Sample data :
TOTAL_STOCK_VALUE VALUE_UNRESTRICTED fiscal_year fiscal_period plant storage_location
336.0 228.0 2019 10 ABC AR40
418.0 209.0 2019 10 ABC IN80
162.0 0.000 2020 04 CTF KK29
86412.0 53060.0 2020 04 ARZ HD91
Desired Output :
TOTAL_STOCK_VALUE VALUE_UNRESTRICTED fiscal_year fiscal_period plant storage_location New
336.0 228.0 2019 10 ABC AR40 32.14%
418.0 209.0 2019 10 ABC IN80 50%
162.0 0.000 2020 04 CTF KK29 100%
86412.0 53060.0 2020 04 ARZ HD91 38.59%
使用过的查询:
select
TOTAL_STOCK_VALUE,
VALUE_UNRESTRICTED,
fiscal_year,
fiscal_period,
plant,
storage_location,
((TOTAL_STOCK_VALUE - VALUE_UNRESTRICTED) / TOTAL_STOCK_VALUE) * 100 over(partition by fiscal_year,fiscal_period,plant,storage_location) as New
from
MyTable
上面的查询没有给出期望的结果并引发错误。 任何帮助将不胜感激。
【问题讨论】:
-
你得到了什么结果?
-
我在你的 sql 中没有看到任何聚合函数或
order by。可以添加试试吗? -
@KoushikRoy 不,我只想执行那个简单的数学运算,但是重要的是,我希望数据被问题中 partition by 子句中提到的那些列分隔。
-
@GordonLinoff 我收到一条错误消息:ParseException:遇到:超出预期:AND、AS、ASC、BETWEEN、BLOCK_SIZE、COMMENT、COMPRESSION、CROSS、DEFAULT、DESC 等..... .
标签: sql hive cloudera impala hue