zoukankan      html  css  js  c++  java
  • [SQL]LeetCode595. 大的国家 | Big Countries

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
    ➤微信公众号:山青咏芝(shanqingyongzhi)
    ➤博客园地址:山青咏芝(https://www.cnblogs.com/strengthen/
    ➤GitHub地址:https://github.com/strengthen/LeetCode
    ➤原文地址:https://www.cnblogs.com/strengthen/p/10450247.html 
    ➤如果链接不是山青咏芝的博客园地址,则可能是爬取作者的文章。
    ➤原文已修改更新!强烈建议点击原文地址阅读!支持作者!支持原创!
    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★

    SQL架构

    1 Create table If Not Exists World (name varchar(255), continent varchar(255), area int, population int, gdp int)
    2 Truncate table World
    3 insert into World (name, continent, area, population, gdp) values ('Afghanistan', 'Asia', '652230', '25500100', '20343000000')
    4 insert into World (name, continent, area, population, gdp) values ('Albania', 'Europe', '28748', '2831741', '12960000000')
    5 insert into World (name, continent, area, population, gdp) values ('Algeria', 'Africa', '2381741', '37100000', '188681000000')
    6 insert into World (name, continent, area, population, gdp) values ('Andorra', 'Europe', '468', '78115', '3712000000')
    7 insert into World (name, continent, area, population, gdp) values ('Angola', 'Africa', '1246700', '20609294', '100990000000')

    There is a table World

    +-----------------+------------+------------+--------------+---------------+
    | name            | continent  | area       | population   | gdp           |
    +-----------------+------------+------------+--------------+---------------+
    | Afghanistan     | Asia       | 652230     | 25500100     | 20343000      |
    | Albania         | Europe     | 28748      | 2831741      | 12960000      |
    | Algeria         | Africa     | 2381741    | 37100000     | 188681000     |
    | Andorra         | Europe     | 468        | 78115        | 3712000       |
    | Angola          | Africa     | 1246700    | 20609294     | 100990000     |
    +-----------------+------------+------------+--------------+---------------+
    

    A country is big if it has an area of bigger than 3 million square km or a population of more than 25 million.

    Write a SQL solution to output big countries' name, population and area.

    For example, according to the above table, we should output:

    +--------------+-------------+--------------+
    | name         | population  | area         |
    +--------------+-------------+--------------+
    | Afghanistan  | 25500100    | 652230       |
    | Algeria      | 37100000    | 2381741      |
    +--------------+-------------+--------------+

    这里有张 World 表

    +-----------------+------------+------------+--------------+---------------+
    | name            | continent  | area       | population   | gdp           |
    +-----------------+------------+------------+--------------+---------------+
    | Afghanistan     | Asia       | 652230     | 25500100     | 20343000      |
    | Albania         | Europe     | 28748      | 2831741      | 12960000      |
    | Algeria         | Africa     | 2381741    | 37100000     | 188681000     |
    | Andorra         | Europe     | 468        | 78115        | 3712000       |
    | Angola          | Africa     | 1246700    | 20609294     | 100990000     |
    +-----------------+------------+------------+--------------+---------------+
    

    如果一个国家的面积超过300万平方公里,或者人口超过2500万,那么这个国家就是大国家。

    编写一个SQL查询,输出表中所有大国家的名称、人口和面积。

    例如,根据上表,我们应该输出:

    +--------------+-------------+--------------+
    | name         | population  | area         |
    +--------------+-------------+--------------+
    | Afghanistan  | 25500100    | 652230       |
    | Algeria      | 37100000    | 2381741      |
    +--------------+-------------+--------------+

    1613ms
    1 # Write your MySQL query statement below
    2 select 
    3     a.name, a.population, a.area
    4 from 
    5     world as a
    6 where 
    7     a.area > 3000000 or a.population > 25000000

    1627ms

    1 # Write your MySQL query statement below
    2 select w.name, w.population, w.area
    3 from World w
    4 where w.area > 3000000 or
    5       w.population > 25000000;  
  • 相关阅读:
    Java面试题及答案整理(持续更新)
    CentOS6.4-mini系统服务列表
    Linux内核编译,模块尺寸变大的解决办法
    Configuration Opennebula3.8 & 4.x Virtual Machines Contextualizing
    CentOS6.3上Opennebula 3.8 VLAN配置
    Ubuntu 12.04 LTS主机名、IP、DNS配置总结
    Linux su
    Git安装配置总结
    Linux CentOS添加163yum源
    Linux 内核编译 modules ehci-hcd, ohci-hcd, uhci-hcd not found
  • 原文地址:https://www.cnblogs.com/strengthen/p/10450247.html
Copyright © 2011-2022 走看看