hive - 带有 Sum 和 group By 的 Hive 表
问题描述
我有一个带有以下数据的 Hive 表。我想根据键将这 6 行转换为 2 行,并希望使用 type='credit' 的行。
key type price1
111 null 1000
111-21 credit 2000
111-31 credit 3000
222 credit 1000
222-21 null 2000
222-31 null 3000
我想 O/p 作为
key type price1
111 credit 6000
222 credit 6000
我已经尝试过以下查询,但没有得到所需的输出,有人可以帮我怎么做。
select key,type,sum(price1) from tablename where type='credit' group by substr(key,3), type;
解决方案
select key, type, sum(price1) from tablename where type = "credit" group by substr(key,1,3)
推荐阅读
- feature-selection - 在审查数据上使用 univariate.model.score 过滤器在 mlr 中进行特征选择
- java - 如果代理不可用,javax.jms.TemporaryTopic.delete() 将无限期阻塞
- android - 如何在 MVVMCross 的 ViewModel 中引用 UI-Component
- apache-spark - 如何正确启动worker
- shell - 命令在 bash 中有效,但在脚本中无效
- java - 在云端点 v2 中实现部分响应 - Java
- apache-spark - 如何将数据从hive导出到kafka
- android - Xam.Plugin.GeoLocator 中的 System.Threading.Tasks.TaskCanceledException
- eclipse - 安装 sonarLint eclipse Juno 时出错
- rest - 当其他 HTTP 动词的路径有多个参数时,用于 POST 的 RESTful API?