SQL。如果列没有值,则不显示行

时间:2017-09-14 22:00:04

标签: sql database

列出以'e'作为名字或姓氏的第4个字母且具有假名的作者。

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)

2 个答案:

答案 0 :(得分:2)

CALL SYSCS_UTIL.SYSCS_EXPORT_QUERY 
   ('SELECT a.ID, a.COLOR, a.TYPE, b.DESC
       FROM TABLE_1 a left join TABLE_2 b on a.ID=b.ID',
    '/path/to/test.txt',',','"','UTF-8');

答案 1 :(得分:1)

你需要括号:

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是多余的。无论如何,我建议你留下它,只是为了明确条件。

相关问题