12

我更喜欢 1/0 而不是 t/f,那么在将布尔值转换为整数时应该使用什么?

select coalesce((null::boolean)::int, 0)

或者

select case null::boolean when 't' then 1 else 0 end

……别的?

4

1 回答 1

21

无论您做什么,布尔 null 不等于 false,就像数字 null 不等于零一样。

尝试:

Cast(col1 as integer)

如果您真的想将 null 视为 false ,那么:

case when col1 then 1 else 0 end

虽然这将是一件坏事

于 2013-04-22T08:28:24.640 回答