【发布时间】:2020-10-28 16:06:33
【问题描述】:
我正在尝试将 concat_ws 函数运行到 group by 中,但出现以下错误。是否意味着 Hive 不支持将concat_ws 转换为group by?如果没有,有没有其他的写法?
我在瀑布表中有以下记录(只有年月日):
Year, Month, Date,
2018, 08, 09
2019, 09, 27
2017, 09, 27
2019, 02, 27
2019, 01, 27
2019, 01, 30
2019, 09, 27
2017, 09, 27
2019, 02, 27
2019, 01, 27
2019, 01, 30
..., ..., ...
有没有一种方法可以使用查询将我的记录分组到一些行中,从而将所有年、月和日组合在一起?
查询的最终结果将是两行:
realdate,num
2019-01-27, 4
2019-01-28, 23
2019-01-29, 34
2019-02-01, 8
2019-02-02, 4
我认为查询应该是这样的:
select
concat_ws('-', year, month, day) as realdate,count(*)
from
waterfall_table
where
concat_ws('-', year, month, day) between '2019-01-25' and '2019-02-10'
group by concat_ws('-', year, month, day)
order by concat_ws('-', year, month, day) desc
limit 100
【问题讨论】:
-
更新您的问题并添加适当的数据样本和预期结果......并显示确切的错误消息
-
使用一列添加完整日期以提高查询性能
-
为什么
2019-01-27有 num:4?您的示例数据中只有两个日期2019-01-27
标签: sql hive concatenation