【发布时间】:2015-06-02 12:00:41
【问题描述】:
以下是我尝试从中获取最大计数以及相应的 hour_id 和 id 值的源数据。日期应该只有一行,现在特定日期有多个值。
id hour_id count date
621f50772a36e7 23 14474 20141202
621f50157c2973 0 7190 20141203
621f5077582f54 7 5043 20141225
621f505247c107 11 5023 20141224
621f50251c8b33 10 4943 20141224
621f5076c9327b 18 4901 20150113
621f50044c300e 10 4868 20141212
621f500e10fa5d 12 4858 20141224
621f505242ec27 9 4843 20141224
621f505263bc56 14 4716 20141231
621f50774a456c 19 4712 20141206
621f5077414404 19 4674 20141123
621f5077362f46 19 4666 20141224
621f505246ea97 10 4662 20141225
621f50522c6bf5 13 4626 20141226
621f5076c87607 13 4586 20141231
621f5052297007 17 4574 20141224
我已经试过了:
select max(count) cc
,partition_date
,location_id
,hour_id
from
(
select
l.location_id
, substr(x.evt_timestamp,9,2) as hour_id
, count(1) as count
,partition_date
from prismeventdetails x
join l_cellsite_location l
on x.evt_location = l.location_id
where x.evt_type = '100'
group by l.location_id
,hour_id
,partition_date
order by cc desc limit 500
) c
group by partition_date,location_id,hour_id
但无法得到想要的结果。
为一个日期获取多行。因为我已将 hour_id 包含在 group by
.我想要 hour_id 和 id 值,其中 count 是该 date 的最大值。需要帮助,我们将不胜感激。
【问题讨论】:
-
为什么这个标签是黑斑羚?
-
我正在使用 Impala sql 引擎
-
您使用的是哪个版本的 Impala?
-
我正在使用 Impala 1.2.1 。
-
我的回答能解决你的问题吗?
标签: mysql sql greatest-n-per-group impala