Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这是一个非常基本的查询(与此相关)我无法弄清楚……</p>
假设我有一个像这样的两列表:
A - B 1 - 1 1 - 2 1 - 3 2 - 1 3 - 1 3 - 4
我想得到所有不同的 As没有2 或 3 的 B。使用上面的示例,我想要返回的唯一结果是 As 2 和 3。我该怎么做?
SELECT DISTINCT `A` FROM `t` AS `t1` WHERE NOT EXISTS ( SELECT 1 FROM `t` WHERE `t`.`A` = `t1`.`A` AND `B` in (2,3) );
SQL Fiddle 演示
尝试使用以下代码:
select distinct a from tbl where B not IN(2,3)