【问题标题】:How can I get SQL query result except one specific row?除了一个特定的行,我怎样才能得到 SQL 查询结果?
【发布时间】:2022-01-15 00:17:12
【问题描述】:

我有一个personnel 表。我想获取此表中的所有记录,除了 IT 值为部门且名称为 John 的记录。

这些是我的行:

Name Department
John Computer
John IT
Kevin Medical
Kevin IT
Kevin Pharmacy

这是我的查询

select * 
from personnels per 
where (per.Name = 'John' and per.Department <> 'IT')

这是该查询的结果:

Name Department
John Computer

预期结果

Name Department
John Computer
Kevin Medical
Kevin IT
Kevin Pharmacy

【问题讨论】:

    标签: sql sql-server tsql


    【解决方案1】:

    试试这个;

    SELECT * 
    FROM personnels per
    WHERE NOT (per.Name = 'John' AND per.Department = 'IT')
    

    Demo

    【讨论】:

      【解决方案2】:

      你可以试试这个;

      SELECT * FROM personnels 
      WHERE Name != "John" and Department != "Computer"
      

      【讨论】:

        猜你喜欢
        • 2021-03-22
        • 1970-01-01
        • 2018-01-11
        • 1970-01-01
        • 2011-11-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多