IF vs IIF 和性能差异?

IF vs IIF and performance difference?

我想知道 IF 语句与 Tableau 中的 IIF() 函数有什么区别。然后我找到了这个页面,它解释了语法差异。

Difference between iif and if

但是有人(在研讨会上)也告诉我 IIF() 的性能更好。是真的吗?

语句对比函数

IFIIF的主要区别在于前者是 声明

IF test THEN value END 
IF test THEN value ELSE else END 

而后者是一个函数

IIF(test, then, else, [unknown])

另一个区别,正如在引用的link中提到的 在开头的问题中,后者是否也支持 "unknown" 案例的单独处理的概念。
这里是the documentation from Tableau

IIF(test, then, else, [unknown])

. . .

A boolean comparison may also yield the value UNKNOWN (neither TRUE nor FALSE), usually due to the presence of Null values in test. The final argument to IIF is returned in the event of an UNKNOWN result for the comparison. If this argument is left out, Null is returned.

IF 语句中,未知情况的处理集中在ELSE 块中。来自同一份文件 来自上面引用的 Tableau

The IF THEN ELSE function evaluates a sequence of test conditions and returns the value for the first condition that is true. If no condition is true, the ELSE value is returned.

关于性能差异的声明

至于关于两种构造之间性能差异的说法, 我调查了索赔:

  1. 我进行了相当多的搜索,但我找不到支持该说法的证据,无论是 Tableau 的官方说法还是其他用户的说法。
  2. 我进行了一个小的(轶事)实验,但我无法观察到任何性能 差异(我的测试涉及来自 CSV 文件的 300MB 数据集,并且有 其中有 360 万行,两种方法的执行速度差不多。
  3. 告诉我索赔的 Tableau 员工似乎 back-peddled 我又问了她同样的问题来确认。

所以我会将声明归类为未经证实。

区别如下: IF(Condition, "truevalue", IIF(Condition,"truevalue","falsevalue")) - 该语句如果看到空值将 return "falsevalue".

IIF(Condition, "truevalue", IIF(Condition,"truevalue","falsevalue"), "no value") - 此函数将看到空值和 return "no value".