sql - 如何在 hive 中实现无分组的计数(不同)
问题描述
我想在 hive 中使用 group by 来查找计数(不同的列名)。我的输入是:
name id
a 2
a 3
a 4
b 1
c 4
c 4
d 7
d 9
我的预期输出是
name count
a 3
b 1
c 1
d 2
有人可以告诉我如何在不使用 group by 的情况下实现这一目标。请帮忙
解决方案
group by
没有显式的规范解决方案select
与窗口函数不同:
select distinct name, count(distinct id) over (partition by name)
from t;
就您而言,我强烈推荐以下group by
版本:
select name, count(distinct id)
from t
group by name;
推荐阅读
- php - 如果数据库中的项目不属于当前用户,Laravel 会拒绝通过 URL 访问它吗?
- c++ - Exceptions inside methods c++
- docker - GCP:如何从 VM 实例访问云存储桶
- wordpress - WordPress 用户元数据内联显示多个子页面的内容
- reactjs - 无法弄清楚在反应应用程序中在哪里启动 CronJob
- c# - WPF 使用键盘上的箭头键移动图像
- javascript - NPM 包导入如何解决?
- python - 为什么在连接的插槽显示 QMessageBox 时,editingFinished 信号会生成两次?
- python-3.x - 如何使用 Tweepy 指定 Twitter 端点
- xsl-fo - DITA-OT PDF formatter xsl:attribute-set names 文档