HiveQL中的日历表按周汇总数据?

时间:2019-05-17 18:22:21

标签: hive hiveql

我正在寻找一种方法,可以每周从Hive中的数据源汇总票证。

对语法和蜂巢提供的内容不是很熟悉,我很好奇是否有内置的日历表或每周增加数据的方法吗?

SQL:

SELECT MONTH(ppjira.resolutionDate)
       MONTH, 
       COUNT(*) COUNT
FROM ppjira
WHERE YEAR(ppjira.resolutionDate)=2019
    AND ppjira.status = 'Closed'
GROUP BY MONTH(ppjira.resolutionDate);

结果:

month   count
1   123
2   100
3   75
4   106
5   49

例如,该查询为我提供自开始日期以来特定月份的记录计数,但我正在按周查找明细。

这里的最终目标是显示给定年份的每个星期都有许多张开闭的车票。

我试图做类似以下的事情,但是我相信hiveql和子查询的语法是错误的。

select weeknum, sum(startweek) as starts, sum(endweek) as ends,
       (select count(*) as numstarts
        from ppjira ts
        where DATEPART(WEEK, ts.[created]) <= weeknum and
              datepart(week, ts.[resolutionDate]) >= weeknum
       ) as actives
from ((select DATEPART(WEEK, t.[created]) AS weeknum, 1 as startweek, 0 endweek,
              t.[created] as startdate, NULL as enddate
       from ppjira
      ) union all
      (select DATEPART(WEEK, t.[resolutionDate]) AS weeknum, 0 as startweek, 1 as endweek,
              NULL, t.[resolutionDate] as enddate
       from ppjira
      )
     ) t
group by weeknum
order by 1

有没有内置的方法来实现这一目标?

0 个答案:

没有答案