2016-07-20 37 views
0

我正在使用vertica並在窗口上使用min()窗口函數。但是,對於某些窗口,該函數似乎可以正常工作,但對於某些窗口,它將在同一窗口中返回不同的最小值。有沒有辦法,我俯瞰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

Vertica的哪個確切版本在運行? 'select version();' – woot

+0

@ woot Vertica分析數據庫v7.2.3-0 – Teja

+0

爲什麼窗口定義中的「order by」?我失敗了,所以爲什麼你需要一個'order by'來獲得最小值。通常,用作窗口函數的集合中的「order by」會將其轉換爲「正在運行的聚合」。當您刪除'order by'時,它是否按預期工作? –

回答

1

訂購窗口,以便分區正確組合在一起。

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 

另外,可能不希望以這種方式進行Date_time轉換。更好地避免謂詞上的投射和函數,以便數據庫可以更好地進行優化(並非如此,但您會給它更多的機會)。

where Date_time >= '2016-06-19' and Date_time < '2016-06-20'