美文网首页
SQL语句,如果为空则=0,否则=1

SQL语句,如果为空则=0,否则=1

作者: TinyThing | 来源:发表于2019-08-23 11:33 被阅读0次

postgres有一种单行写法,不推荐使用

sign(COALESCE(length(mobile), 0))

还有

select
    user_id,
    case mobile
        when null then 0
        else 1 end
        as hasMobile
from tb_user;

对于mysql还有一种语法:

IF(mobile = null, 0, 1)

相关文章

网友评论

      本文标题:SQL语句,如果为空则=0,否则=1

      本文链接:https://www.haomeiwen.com/subject/rrpzsctx.html