MySQL - SELECT the name that comes first alphabetically

后端 未结 11 1390
悲&欢浪女
悲&欢浪女 2020-12-24 08:50

I have started to learn MySQL.

Here is the table world:

+-------------+-----------+---------+
|    name     | continent |  area   |
+--         


        
相关标签:
11条回答
  • 2020-12-24 09:12

    what about this sql :

    select distinct continent, 
          (select name 
           from world y where y.continent = x.continent limit 1 ) as name 
    from world x
    
    0 讨论(0)
  • 2020-12-24 09:14

    If you need list each continent alphabetically, you have use

         SELECT * from world ORDER by continent
    

    But, If you nedd list each country your have use

         SELECT * from world ORDER by name
    
    0 讨论(0)
  • 2020-12-24 09:18

    This is a simple aggegation:

    SELECT continent, MIN(name) AS name
    FROM world 
    GROUP BY continent
    ORDER by continent
    
    0 讨论(0)
  • 2020-12-24 09:18
    Select distinct continent, name from world x 
    where name <=All (Select name from world y where x.continent=y.continent)
    
    0 讨论(0)
  • 2020-12-24 09:21

    The SqlZoo solution would better look like this:

    SELECT continent, name FROM world x
    WHERE name <= ALL
      (SELECT name FROM world y WHERE y.continent=x.continent)
    
    0 讨论(0)
提交回复
热议问题