msyql学习1

查询满足任意条件之一

±------------±--------+
| Column Name | Type |
±------------±--------+
| name | varchar |
| continent | varchar |
| area | int |
| population | int |
| gdp | int |
±------------±--------+
name 是这张表的主键。
这张表的每一行提供:国家名称、所属大陆、面积、人口和 GDP 值。

如果一个国家满足下述两个条件之一,则认为该国是 大国 :

面积至少为 300 万平方公里(即,3000000 km2),或者
人口至少为 2500 万(即 25000000)
编写一个 SQL 查询以报告 大国 的国家名称、人口和面积。

where/or

or在数据少时使用 ,数据量大使用会破坏索引导致性能降低,。
例1:select country,area from world where area >= 5000000 or pop >=2500000

where/union

数据量大推荐使用union
例2:select t.country,t.area from world t where t.area >= 5000000 union select t.country,t.area from world t where t.pop >= 25000000

超过5名学生的课

表: Courses

±------------±--------+
| Column Name | Type |
±------------±--------+
| student | varchar |
| class | varchar |
±------------±--------+
(student, class)是该表的主键列。
该表的每一行表示学生的名字和他们注册的班级。

编写一个SQL查询来报告 至少有5个学生 的所有班级。
例1;select class from Courses group by class having count(distinct student)>=5

借鉴

例2:select class from (select class count(distinct student) as num from Courses group by class ) as temp where num>=5
例3:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值