-----------------------
country | city | ids
-----------------------
India Mumbai 1
India Chennai 2
India Kolkata 3
---------------------
USA New York 2
USA Utah 3
---------------------
Run Code Online (Sandbox Code Playgroud)
我从表中给出了一个样本.从表中,我试图查询所有没有id 1的国家.我写了这个(国家没有包含在Where条件中,因为它需要适用于表中的所有国家).
Select * from Countries
WHERE id<>1
Run Code Online (Sandbox Code Playgroud)
我懂了.
-----------------------
country | city | ids
-----------------------
India Chennai 2
India Kolkata 3
---------------------
USA New York 2
USA Utah 3
---------------------
Run Code Online (Sandbox Code Playgroud)
但我需要输出只包含USA(没有id = 1).这有什么解决方法吗?
SELECT * from Countries WHERE country not in
(SELECT country from Countries WHERE id=1)
Run Code Online (Sandbox Code Playgroud)