我正在使用vertica并在窗口上使用min()窗口函数。但是,该函数似乎对某些窗口工作正常,但对于某些窗口,它在同一窗口中返回不同的最小值。有什么我在忽视
select visid_high, visid_low, visit_num, date_time, visit_page_num,
min(visit_page_num) over (partition by visid_high , visid_low , visit_num order by date_time) as min_hotelinfo
from prd_omniture_hit_data_all where pagename='Hotel Info - Home' and date(Date_time)='2016-06-19' order by visid_high, visid_low, visit_num, date_time
这适用于某些窗口并返回结果如下
visid_high visid_low visit_num date_time visit_page_num min_hotelinfo
1000025785676989783 3541599610445607061 1 6/19/2016 8:54 2 2
1000025785676989783 3541599610445607061 1 6/19/2016 8:55 4 2
1000025785676989783 3541599610445607061 1 6/19/2016 8:55 5 2
visid_high visid_low visit_num date_time visit_page_num min_hotelinfo
1000334043872452151 13928857828543794490 1 6/19/2016 14:56 2 2
1000334043872452151 13928857828543794490 1 6/19/2016 14:57 6 2
1000334043872452151 13928857828543794490 1 6/19/2016 14:57 7 2
1000334043872452151 13928857828543794490 2 6/19/2016 16:09 2 2
10006241273945967252 17961652664059791311 1 6/19/2016 20:09 2 2
10006241273945967252 17961652664059791311 1 6/19/2016 20:09 4 2
10006241273945967252 17961652664059791311 1 6/19/2016 20:10 8 2
但是,对于某些窗口,它无法正常运行
visid_high visid_low visit_num date_time visit_page_num min_hotelinfo
10007599756616641840 269931436307846555 2 6/19/2016 19:51 2 2
10007599756616641840 269931436307846555 2 6/19/2016 19:52 3 2
10007599756616641840 269931436307846555 2 6/19/2016 19:52 5 2
10007599756616641840 269931436307846555 2 6/19/2016 19:53 7 2
10007599756616641840 269931436307846555 2 6/19/2016 19:53 9 2
10007599756616641840 269931436307846555 2 6/19/2016 19:53 10 **10**
10009683770139214971 14890994612952617462 2 6/19/2016 8:03 5 5
10009683770139214971 14890994612952617462 2 6/19/2016 8:03 7 **5**
10009683770139214971 14890994612952617462 2 6/19/2016 8:09 26 **26**
10009683770139214971 14890994612952617462 2 6/19/2016 8:12 28 26
10009683770139214971 14890994612952617462 2 6/19/2016 8:13 30 26
10009683770139214971 14890994612952617462 2 6/19/2016 8:14 32 26
10009683770139214971 14890994612952617462 2 6/19/2016 8:15 36 26
10009683770139214971 14890994612952617462 2 6/19/2016 8:17 40 26
visid_high visid_low visit_num date_time visit_page_num min_hotelinfo
10012413883034897266 8201606845758098188 1 6/19/2016 7:22 4 4
10012413883034897266 8201606845758098188 1 6/19/2016 7:24 5 4
10012413883034897266 8201606845758098188 1 6/19/2016 7:24 8 4
10012413883034897266 8201606845758098188 1 6/19/2016 7:24 7 4
10012413883034897266 8201606845758098188 1 6/19/2016 7:24 6 **4**
10012413883034897266 8201606845758098188 1 6/19/2016 8:04 16 **16**
10012413883034897266 8201606845758098188 1 6/19/2016 8:06 20 16
10012413883034897266 8201606845758098188 1 6/19/2016 8:06 25 16
10012413883034897266 8201606845758098188 1 6/19/2016 8:07 28 16
10012413883034897266 8201606845758098188 1 6/19/2016 8:07 30 16
答案 0 :(得分:1)
订购窗口,以便分区正确组合在一起。
controller.expire_fragment(key)
另外,可能不希望以这种方式强制转换Date_time。最好避免在谓词上进行转换和函数,以便数据库可以更好地进行优化(不是它会,但你会给它更多的机会)。
select visid_high, visid_low, visit_num, date_time, visit_page_num,
min(visit_page_num) over
(partition by visid_high, visid_low, visit_num
order by visid_high, visid_low, visit_num) as min_hotelinfo
from prd_omniture_hit_data_all
where pagename = 'Hotel Info - Home'
and date(Date_time) = '2016-06-19'
order by visid_high, visid_low, visit_num, date_time