SQL显示多个列

时间:2014-02-11 09:44:23

标签: mysql sql

我要做的是显示有关来自亚洲和欧洲的国家的所有信息,而不是其他大洲。然后按大陆订购。我只是遗漏了一些明显的东西,但它是什么?

如果我把AND放在亚洲和欧洲之间,那么它会尝试显示来自亚洲和欧洲的国家,所以这样做是不行的,但如果我放OR,那么它只会显示亚洲。

我的代码是什么样的;

SELECT * 
FROM country
WHERE Continent = 'Asia' AND 'Europe'
ORDER BY Continent DESC;

5 个答案:

答案 0 :(得分:6)

尝试以下

SELECT * FROM country
WHERE Continent in ('Asia','Europe')
ORDER BY Continent DESC;

答案 1 :(得分:2)

SELECT * FROM country
WHERE Continent IN ('Asia','Europe')
ORDER BY Continent DESC;

OR

SELECT * FROM country
WHERE Continent ='Asia' OR Continent= 'Europe'
ORDER BY Continent DESC;

答案 2 :(得分:1)

SELECT * FROM country
WHERE Continent = 'Asia' OR Continent = 'Europe'
ORDER BY Continent DESC;

答案 3 :(得分:1)

试试这个

SELECT * FROM country
WHERE Continent In( 'Asia' , 'Europe')
ORDER BY Continent DESC;

(OR)

SELECT * FROM country
WHERE Continent ='Asia' OR Continent= 'Europe'
ORDER BY Continent DESC;

(OR)

SELECT * FROM country
WHERE Continent ='Asia'
ORDER BY Continent DESC;
UNION ALL
SELECT * FROM country
WHERE Continent ='Europe'
ORDER BY Continent DESC;

答案 4 :(得分:-2)

SELECT *
FROM country
WHERE Continent = "Africa" OR Continent = "Australia"
ORDER BY Continent DESC; 

如果你想要非洲人和澳大利亚人,那就

SELECT *
FROM country
WHERE !(Continent = "Africa" AND Continent = "Australia") 
ORDER BY Continent DESC;