NOT IN vs IN Do Not Return Complimentary Results

后端 未结 4 958
灰色年华
灰色年华 2021-02-11 10:03

Hi I am working through example #7 from the sql zoo tutorial: SELECT within SELECT. In the following question

\"Find each country that belongs to a continent where all p

4条回答
  •  难免孤独
    2021-02-11 10:23

    why use a sub query?

    try using:

    SELECT name, continent, population FROM world 
    WHERE population > 25000000
    

    and/or

    SELECT name, continent, population FROM world 
    WHERE population <= 25000000
    

    the column of your condition: "population" is in the FROM table: "world". There is no need to use a sub query of the same table "world" again, just use the "population" column directly in the WHERE

    or are you trying to do this:

    SELECT name, continent, population FROM world 
    WHERE continent NOT IN (
        SELECT continent FROM world
        GROUP BY continent 
        HAVING SUM(population) > 25000000)
    

    notice the: SUM(), GROUP BY, and HAVING

提交回复
热议问题