不要 return row if name= xyz with count=0

Do not return row if name= xyz with count=0

我不想 return 我的 select table for Name = XYZ with count = 0.

            +------+-------+--------+
            | Name | count | Number |
            +------+-------+--------+
            | XYZ  |     0 |      1 |
            | ABC  |    12 |     56 |
            | YYYY |     0 |      1 |
            | DDD  |     0 |     56 |
            | XYZ  |    14 |     58 |
            +------+-------+--------+

结果:

            +------+-------+--------+
            | Name | count | Number |
            +------+-------+--------+
            |
            | ABC  |    12 |     56 |
            | YYYY |     0 |      1 |
            | DDD  |     0 |     56 |
            | XYZ  |    14 |     58 |
            +------+-------+--------+

只需使用 where 子句过滤掉。您的要求的直接翻译是:

select t.*
from mytable t
where not (name = 'XYZ' and cnt = 0)

你也可以表达这个or(假设列不可为空):

where name <> 'XYZ' or cnt <> 0

注意:count 是语言关键字,因此列名不是很好的选择。我在查询中将其重命名为 cntnumber.

也是如此