1
以下是我有表,总结日期,数到最小和最大日期按时间间隔 - SQL
City date count
Seattle 2016-07-14 10
Seattle 2016-07-15 20
Seattle 2016-07-16 30
Seattle 2016-07-18 40
Seattle 2016-07-19 50
Seattle 2016-07-20 60
Seattle 2016-07-25 70
Seattle 2016-07-26 80
Bellevue 2016-07-21 90
Bellevue 2016-07-22 100
Bellevue 2016-07-23 110
Bellevue 2016-07-25 120
Bellevue 2016-07-26 130
Bellevue 2016-07-27 140
Bellevue 2016-08-10 150
Bellevue 2016-08-11 160
Bellevue 2016-08-12 170
我想总结此表为日期间隔,其中每一行都将包含每个间隔的日期。每当有一天中断时,我想创建另一行。我的样本输出应该如下,
City min_date max_date sum_count
Seattle 2016-07-14 2016-07-16 60
Seattle 2016-07-18 2016-07-20 150
Seattle 2016-07-25 2016-07-26 150
Bellevue 2016-07-21 2016-07-23 300
Bellevue 2016-07-25 2016-07-27 390
Bellevue 2016-08-10 2016-08-12 480
在这里,如果我们可以看到,每当有日期的突破,创建一个新的条目,并计数跨越求和。我想在日期中断时创建一个条目。
我试过,
select city, min(date), max(date) , sum(count) from table
group by city
,但这里只给出了两行。
任何人都可以帮我在Hive中做这件事吗?
我们应该在这里加群的城市吗? – Observer
@Observer。 。 。大声笑。是的,这将使查询正确。 –