[英]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.