【发布时间】:2016-10-03 12:41:51
【问题描述】:
我知道在其他语言中,您可以使用某些东西(通常是 !)来表示以下内容的反义词。有没有办法在 MySQL 中做这样的事情?
例如,我有这个查询来选择不为空或空白的所有内容:
select * from `invoices` where `Notes`>'';
但是有没有办法做相反的事情?因为目前我只知道可以重写这样的查询
select * from `invoices` where ifnull(`Notes`,'')='';
但这消除了在Notes 列上或以这种方式建立索引的机会
select * from `invoices` where (`Notes` is null or `Notes`='');
但是那个比类似的要长得多
select * from `invoices` where !`Notes`>'';
这将是理想的。
【问题讨论】:
-
为什么不将笔记设为“不可为空”,默认值为“”?
-
where not notes >'';虽然我不确定这是否会使用索引。
标签: mysql sql select logical-operators