hive - HIVEQL,每天记录的数量
问题描述
我在 hive 中有一个数据库,它的结构如下:
+--------+------------------+---------+
| rating | date | version |
+--------+------------------+---------+
| 3 | 2021-07-01 12:13 | 2.1.9 |
| 5 | 2021-07-01 10:39 | 2.2.6 |
| 4 | 2021-07-02 10:24 | 2.2.7 |
| 5 | 2021-07-02 05:37 | 3.2.4 |
| 1 | 2021-07-02 21:40 | 3.2.5 |
如何使用 HiveQL 获取每天和每月的记录数?
解决方案
每天计算:
select substr(`date`,1,10) as `day`,
count(*) cnt
from table_name
group by substr(`date`,1,10);
每月:
select substr(`date`,1,7) as `month`,
count(*) cnt
from table_name
group by substr(`date`,1,7);
推荐阅读
- python - mongoengine - RuntimeError:生成器引发 StopIteration
- object-detection - 无法使用不同的 coreml 对象实时捕获对象检测
- javascript - 通过chrome扩展将按钮插入当前页面,但某些方法不起作用
- ios - 如何删除应用内购买:从我的 iOS 应用中自动更新订阅
- html - favicon.ico 缺少 32x32 48x48 的大小,尽管它已声明
- javascript - 如何在 JavaScript 文件(.js 扩展名)中禁止 JSX 语法
- postgresql - 使用 Peewee 在 Postgresql 中将浮点数转换为时间戳
- javascript - 单击图像时更改路径。单击其他路径时,反转以前的路径并将新路径应用于当前单击的路径
- google-api - Google urlshortener api 显示 403 错误
- sql - SQL 时间间隔数据