代码之家  ›  专栏  ›  技术社区  ›  rap-2-h

如何匹配非空+非空?

  •  19
  • rap-2-h  · 技术社区  · 9 年前

    我必须在一个混乱的数据库上做一些查询。某些列填充有 null 或空字符串。我可以这样做一个查询:

    select * from a where b is not null and b <> '';
    

    但这个案子有捷径吗?(匹配每个“非空”值)类似于:

    select * from a where b is filled;
    
    2 回复  |  直到 5 年前
        1
  •  41
  •   Clodoaldo Neto    9 年前

    只是:

    where b <> ''
    

    会做你想做的事 null <> '' 为空,将不返回该行

        2
  •  2
  •   Steve Smith    9 年前

    select * from a where COALESCE(b, '') <> '';