2017-02-27 32 views
0

我試圖創建具有以下邏輯蜂房觀點:如何在獨特的子句中執行CASE語句?

create view test.view as 
select 
distinct(
    case 
    when substr(value_1, 1, 10) < "2016-01-01" then 
    regexp_extract(value_2,'(?i-sx:\\|([1-9][0-9]{0,3}x[1-9][0-9]{0,3})\\|)',1) 
    else 
    split(value_2, '\\|')[5] 
    end 
) as value_3 
from test.table; 

但是當我運行它,我得到以下的輸出:

FAILED: ParseException line 128:2 cannot recognize input near 'distinct' '(' 'case' in select expression 

有誰知道我可以寫這樣我不會得到一個錯誤?或者告訴我爲什麼會發生這種情況?

+0

忽視誤差,您是否介意加入一個數據樣本?我不知道你在這裏試圖做什麼 –

回答

1

distinct不是功能。它適用於所有選定的列,並生成所有的選定列的唯一組合。

試試這個:

select distinct case 
     when substr(value_1, 1, 10) < "2016-01-01" 
      then regexp_extract(value_2, '(?i-sx:\\|([1-9][0-9]{0,3}x[1-9][0-9]{0,3})\\|)', 1) 
     else split(value_2, '\\|') [5] 
     end as value_3 
from test.table; 

所以,這樣的:

select distinct (col), col2 

是一樣的:

select distinct col, col2 
+0

我其實並不知道任何支持'select col,distinct col2'的提供者 –