簡體   English   中英

蜂巢sql排序查詢比較最后一個值

[英]hive sql sorted query compare last value

我的記錄中有按ID和編號排序的記錄。 我必須建立一個邏輯,在該邏輯中檢查它上面的行,如果它符合特定條件,它將被分配與另一列相同的值。 邏輯如下

if [row-1:id] != [id] and is null ([first_time])
then [my_date]
else [first_time]
endif

在我的查詢中

select
 case when
   lag(my_date) over (partition by id  order by id ASC, first_time ASC) and  
   first_time is Null then my_date
   else first_time
   end
   from
   mytable 

我上面編寫的查詢將無法編譯。 這是處理上面列出的表達式的正確查詢邏輯嗎?

您有lag() ,但沒有比較。 您似乎想要以下內容:

select (case when first_time is null
                  lag(id, 1, -1) over (order by ?) <> id
             then my_date else first_time
        end)
from my_table;

? 用於指定表中順序的列-“上一行”的定義

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM