HIVEQL,每天计算记录数量

时间:2021-07-06 16:54:16

标签: 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 获取每天和每月的记录数?

1 个答案:

答案 0 :(得分:0)

每天计数:

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); 
相关问题