当前位置:网站首页>【每日SQL打卡】DAY 24丨不同国家的天气类型【难度简单】
【每日SQL打卡】DAY 24丨不同国家的天气类型【难度简单】
2022-07-29 11:42:00 【不吃西红柿】
难度简单
SQL架构
国家表:Countries
+---------------+---------+
| Column Name | Type |
+---------------+---------+
| country_id | int |
| country_name | varchar |
+---------------+---------+
country_id 是这张表的主键。
该表的每行有 country_id 和 country_name 两列。天气表:Weather
+---------------+---------+
| Column Name | Type |
+---------------+---------+
| country_id | int |
| weather_state | varchar |
| day | date |
+---------------+---------+
(country_id, day) 是该表的复合主键。
该表的每一行记录了某个国家某一天的天气情况。写一段 SQL 来找到表中每个国家在 2019 年 11 月的天气类型。
天气类型的定义如下:当 weather_state 的平均值小于或等于15返回 Cold,当 weather_state 的平均值大于或等于 25 返回 Hot,否则返回 Warm。
你可以以任意顺序返回你的查询结果。
查询结果格式如下所示:
Countries table:
+------------+--------------+
| country_id | country_name |
+------------+--------------+
| 2 | USA |
| 3 | Australia |
| 7 | Peru |
| 5 | China |
| 8 | Morocco |
| 9 | Spain |
+------------+--------------+
Weather table:
+------------+---------------+------------+
| country_id | weather_state | day |
+------------+---------------+------------+
| 2 | 15 | 2019-11-01 |
| 2 | 12 | 2019-10-28 |
| 2 | 12 | 2019-10-27 |
| 3 | -2 | 2019-11-10 |
| 3 | 0 | 2019-11-11 |
| 3 | 3 | 2019-11-12 |
| 5 | 16 | 2019-11-07 |
| 5 | 18 | 2019-11-09 |
| 5 | 21 | 2019-11-23 |
| 7 | 25 | 2019-11-28 |
| 7 | 22 | 2019-12-01 |
| 7 | 20 | 2019-12-02 |
| 8 | 25 | 2019-11-05 |
| 8 | 27 | 2019-11-15 |
| 8 | 31 | 2019-11-25 |
| 9 | 7 | 2019-10-23 |
| 9 | 3 | 2019-12-23 |
+------------+---------------+------------+
Result table:
+--------------+--------------+
| country_name | weather_type |
+--------------+--------------+
| USA | Cold |
| Austraila | Cold |
| Peru | Hot |
| China | Warm |
| Morocco | Hot |
+--------------+--------------+
USA 11 月的平均 weather_state 为 (15) / 1 = 15 所以天气类型为 Cold。
Australia 11 月的平均 weather_state 为 (-2 + 0 + 3) / 3 = 0.333 所以天气类型为 Cold。
Peru 11 月的平均 weather_state 为 (25) / 1 = 25 所以天气类型为 Hot。
China 11 月的平均 weather_state 为 (16 + 18 + 21) / 3 = 18.333 所以天气类型为 Warm。
Morocco 11 月的平均 weather_state 为 (25 + 27 + 31) / 3 = 27.667 所以天气类型为 Hot。
我们并不知道 Spain 在 11 月的 weather_state 情况所以无需将他包含在结果中。边栏推荐
猜你喜欢

Proficient in audio and video development can really do whatever you want

一次node文件操作过多排查过程总结

Kubernetes基本概念

2.3插入排序

Alibaba architects spent a year sorting out the "Lucene advanced document", and you are also a big factory employee!

QT's user-defined interface (borderless and movable)

three.js 报错信息 RGBELoader.js:46 RGBELoader Bad File Format: bad initial token

【图像处理】基于中轴变换实现图像骨架提取附matlab代码

MySql启动、连接sqlog、主从复制、双机热备(开机时)

DNS协议、ICMP协议、NAT技术
随机推荐
LMO·3rd - 报名通知
Building and sharing the root of the digital world: Alibaba Cloud builds a comprehensive cloud-native open source ecosystem
Golang realizes file upload and download
Self collection online computer wallpaper PHP source code v2.0 adaptive end
DNS协议、ICMP协议、NAT技术
mapbox 地图 生成矢量数据圆
2.1冒泡排序(Bubble Sorting)
Xiaoxiao authorization system V5.0 happy version
Insights into the development of the enterprise live broadcast industry in 2022
[image processing] image skeleton extraction based on central axis transformation with matlab code
面试官培训课件(非常实用的企业内训课件)
微信云托管入门与实践
7月3日文: 表面上有危险,实属安全周期,大概率会快速上扬的个股
Watch the open source summit first | quick view of the sub Forum & Activity agenda on July 29
自采集在线电脑壁纸php源码v2.0自适应端
TCP和UDP
CSDN TOP1“一个处女座的程序猿“如何通过写作成为百万粉丝博主
如何在匹配行之前使用 grep 显示文件名和行号
【Unity3D】角色控制器(CharacterController)
如何使用“COPY –link”加速 Docker 构建和优化缓存