HIVEQL,计算每天的记录量

HIVEQL, COUNT AMOUNT OF RECORDS PER DAY

我在 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);