美文网首页
leedCode 大国家问题

leedCode 大国家问题

作者: 赵荣晖 | 来源:发表于2018-10-25 20:20 被阅读0次

这里有张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 |

+--------------+-------------+--------------+

一、创建表的sql 略

知识点:可能是比较哪种查询方式比较快吧,比较基础的问题。

二、使用or的方式,全表扫描。写法简单,常见方式

SELECT name,population,area FROM WORLD WHERE AREA > 3000000 OR POPULATION >25000000

三、使用union的方式,范围扫描。数据量大时,会更快

SELECT name,population,area FROM WORLD WHERE AREA > 3000000 

union

SELECT name,population,area FROM WORLD WHERE POPULATION >25000000

leetcode提供的耗时没有参考意义,相同sql多次执行耗时都不相同

相关文章

  • leedCode 大国家问题

    这里有张World表 +-----------------+------------+------------+-...

  • golang 语言 LeedCode104 二叉树的最大深度

    golang 语言 LeedCode104 二叉树的最大深度

  • LeedCode 旋转图像

    LeetCode 旋转图像 给定一个 *n *× n 的二维矩阵表示一个图像。 将图像顺时针旋转 90 度。 思路...

  • 2018-03-14

    leedcode——97. Interleaving String Givens1,s2,s3, find whe...

  • Sep-26-2018

    争取每周做五个LeedCode题,定期更新,难度由简到难 Title: Two Sum Description: ...

  • Oct-18-2018

    争取每周做五个LeedCode题,定期更新,难度由简到难 Title: Implement strStr() De...

  • Oct-17-2018

    争取每周做五个LeedCode题,定期更新,难度由简到难 Title: Remove Element Descri...

  • Oct-16-2018

    争取每周做五个LeedCode题,定期更新,难度由简到难 Title: Remove Duplicates fro...

  • Oct-23-2018

    争取每周做五个LeedCode题,定期更新,难度由简到难 Title: Search Insert Positio...

  • Oct-08-2018

    争取每周做五个LeedCode题,定期更新,难度由简到难 Title: Roman to Integer Desc...

网友评论

      本文标题:leedCode 大国家问题

      本文链接:https://www.haomeiwen.com/subject/klactqtx.html