列出作者姓名或姓氏中的第4個字母爲'e',並具有化名的作者。SQL。如果列沒有值,則不顯示行
select * from authors where last_name like '___e%' or first_name like '___e%' and pseudonym is not null and pseudonym <> ' ';
The output still show the row where pseudonym are null (picture)
列出作者姓名或姓氏中的第4個字母爲'e',並具有化名的作者。SQL。如果列沒有值,則不顯示行
select * from authors where last_name like '___e%' or first_name like '___e%' and pseudonym is not null and pseudonym <> ' ';
The output still show the row where pseudonym are null (picture)
您需要括號:
select *
from authors
where (last_name like '___e%' or first_name like '___e%') and
pseudonym is not null and
pseudonym <> ' ';
如果你正在學習SQL,然後使用時,您的情況有一個以上的邏輯運算符括號(如(AND
)和(OR
))。
比較is not null
是多餘的。無論如何,我建議你放棄它,只是爲了明確條件。
select *
from authors
where (last_name like '___e%' or first_name like '___e%') and
trim(pseudonym) is not null;