我知道在其他语言中,您可以使用某些东西(通常是 !
)来表示后面任何内容的相反内容。有没有办法在 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`>'';
这将是理想的。
最佳答案
SQL 有一个 not
运算符:
SELECT * FROM `invoices` WHERE NOT (`Notes`>'');
-- Here -----------------------^
关于MySQL 条件相反,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37614530/