[英]sql/spark-sql: if statement syntax in a query
我正在研究一些現有的spark-sql代碼,嘗試將兩個表連接到表中,如下所示:
items_t1_t2 as (
select *,
if(id_t1 is not Null, True, False) as in_t1,
if(id_t2 is not Null, True, False) as in_t2
from item_t2 full join item_t1
on id_t2 = id_t1)
我想知道為什么if括號中包含三個元素? if語句在這里意味着什么以及它在這里如何工作? 非常感謝!
Spark SQL(和某些其他SQL系統)中的“ IF”語句具有三個子句:
IF (condition_to_evaluate, result_if_true, result_if_false)
例如,在這種情況下,表達式:
IF(id_t1 IS NOT NULL, True, False) AS in_t1
在邏輯上等效於這一點:
id_t1 IS NOT NULL AS in_t1
或者, in_t1
一種說法: in_t1
只是一個標志,上面寫着“ if id_t1不為null”, in_t2
和id_t2
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.