如何在WHERE中使用多个子查询

时间:2014-06-04 23:22:46

标签: mysql sql

刚开始学习SQL,经过一百万次谷歌搜索,我无法找到答案。

SELECT name, population FROM world
WHERE population > (SELECT population FROM world 
WHERE name = 'Canada');
WHERE population < (SELECT population FROM world
WHERE name = 'Poland');

我知道你可以使用&#34;加入&#34;或类似的东西但使用子查询我该怎么做?基本上,我寻找的人口比加拿大人大,但比波兰人少。

4 个答案:

答案 0 :(得分:1)

你几乎拥有它。只需要一个AND而不是分号。

SELECT name, population FROM world
WHERE population > (SELECT population FROM world WHERE name = 'Canada')
AND
WHERE population < (SELECT population FROM world WHERE name = 'Poland');

:)

答案 1 :(得分:0)

SELECT name, population FROM world
WHERE population > (SELECT population FROM world 
WHERE name = 'Canada') AND 
population < (SELECT population FROM world
WHERE name = 'Poland');

答案 2 :(得分:0)

尝试使用AND

SELECT name, population FROM world
WHERE population > (SELECT population FROM world WHERE name = 'Canada')
AND population < (SELECT population FROM world WHERE name = 'Poland');

答案 3 :(得分:0)

阅读基本语法。

尝试

SELECT name, population FROM world WHERE population > (SELECT population FROM world WHERE name = 'Canada'); AND population < (SELECT population FROM world WHERE name = 'Poland');