试图解析这个SQL

phi*_*ogg 5 mysql sql

我试图理解这个SQL(来自MySQL安装)实际上是做什么的:

IF(coalesce(a.entity_id, 0) != 0, 0, 1)
Run Code Online (Sandbox Code Playgroud)

虽然我理解coalesce的作用,但我不明白IF语句是如何修改它的.

And*_*kov 3

我认为:

coalesce(a.entity_id, 0) - 返回第一个非空值,

如果 a.entity_id 不为 null,则 if 的结果为 0,否则为 1。

a.entity_id = null =>合并=0=>if=1

a.entity_id 不为 null => 合并 = a.entity_id => if = 0