【问题标题】:HIVEQL, COUNT AMOUNT OF RECORDS PER DAYHIVEQL,每天记录的数量
【发布时间】:2021-07-06 16:54:16
【问题描述】:

我在 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 获取每天和每月的记录数?

【问题讨论】:

    标签: hive hiveql


    【解决方案1】:

    每天计数:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-26
      • 1970-01-01
      • 1970-01-01
      • 2018-11-15
      • 1970-01-01
      • 2012-03-03
      • 1970-01-01
      • 2022-07-01
      相关资源
      最近更新 更多