当前位置:网站首页>SQL练习第一题
SQL练习第一题
2022-04-23 06:15:00 【山顶看数据】
题目
表名:macro_index_data
字段名:
数据期(年月) 地区代码 指标代码 指标类型 (增速、总量) 指标值 数据更新时间
occur_period area_code index_code index_type index_value update_time
说明:罗湖区的区划代码为 440305000000、GDP指标代码为gmjj_jjzl_01、指标类型的枚举值分别是增速(TB)、总量(JDZ)
问题
请写出,2020年4个季度中GDP的增速都超过罗湖区同期的区有哪些
答案
-- 求出罗湖区2020年4个季度的GDP增速
select
area_code,
sum (case when month('occur_period') between 1 and 3 then index_value else 0 end)),
sum (case when month('occur_period') between 4 and 6 then index_value else 0 end)),
sum (case when month('occur_period') between 7 and 9 then index_value else 0 end)),
sum (case when month('occur_period') between 10 and 12 then index_value else 0 end))
from macro_index_data
where area_code = '440305000000'
and index_code = 'gmjj_jjzl_01'
and index_type = 'TB'
and year('occur_period') = 2020
group by area_code
-- 求出其他区中的GDP增速
select
area_code,
sum (case when month('occur_period') between 1 and 3 then index_value else 0 end)),
sum (case when month('occur_period') between 4 and 6 then index_value else 0 end)),
sum (case when month('occur_period') between 7 and 9 then index_value else 0 end)),
sum (case when month('occur_period') between 10 and 12 then index_value else 0 end))
from macro_index_data
where area_code <> '440305000000'
and index_code = 'gmjj_jjzl_01'
and index_type = 'TB'
and year('occur_period') = 2020
group by area_code
-- 整合函数
with t1 as (
select
area_code,
sum (case when month('occur_period') between 1 and 3 then index_value else 0 end)) `one`,
sum (case when month('occur_period') between 4 and 6 then index_value else 0 end)) `two`,
sum (case when month('occur_period') between 7 and 9 then index_value else 0 end)) `three`,
sum (case when month('occur_period') between 10 and 12 then index_value else 0 end) `four`)
from macro_index_data
where area_code = '440305000000'
and index_code = 'gmjj_jjzl_01'
and index_type = 'TB'
and year('occur_period') = 2020
group by area_code
),
t2 as (
select
area_code,
sum (case when month('occur_period') between 1 and 3 then index_value else 0 end)) `one`,
sum (case when month('occur_period') between 4 and 6 then index_value else 0 end)) `two`,
sum (case when month('occur_period') between 7 and 9 then index_value else 0 end)) three`,
sum (case when month('occur_period') between 10 and 12 then index_value else 0 end)) `four`
from macro_index_data
where area_code <> '440305000000'
and index_code = 'gmjj_jjzl_01'
and index_type = 'TB'
and year('occur_period') = 2020
group by area_code
)
select t2.area_code
from
t1 join t2 on t1.area_code = t2.area_code
where
t1.one < t2.one and
t1.two < t2.two and
t1.three < t2.three and
t1.four < t2.four;
版权声明
本文为[山顶看数据]所创,转载请带上原文链接,感谢
https://blog.csdn.net/li1579026891/article/details/122698133
边栏推荐
猜你喜欢
imx6ull-qemu 裸机教程2:USDHC SD卡
【点云系列】Relationship-based Point Cloud Completion
关于短视频平台框架搭建与技术选型探讨
Wechat applet uses wxml2canvas plug-in to generate some problem records of pictures
Are realrange and einsum really elegant
关于短视频技术轮廓探讨
网络层重要知识(面试、复试、期末)
pth 转 onnx 时出现的 gather、unsqueeze 等算子
美摄科技推出桌面端专业视频编辑解决方案——美映PC版
LPDDR4笔记
随机推荐
enforce fail at inline_ container. cc:222
基于open mv 搭配stm32循迹
Chapter 3 pytoch neural network toolbox
Paddleocr image text extraction
Swin transformer to onnx
自组网灵活补盲|北峰油气田勘测解决方案
The simplest and complete example of libwebsockets
《Attention in Natural Language Processing》翻译
GIS实用小技巧(三)-CASS怎么添加图例?
rearrange 和 einsum 真的优雅吗
unhandled system error, NCCL version 2.7.8
PyTorch 22. PyTorch常用代码段合集
EasyUI combobox determines whether the input item exists in the drop-down list
机器视觉系列(02)---TensorFlow2.3 + win10 + GPU安装
被 onnx.checker.check_model 检查出的常见错误
南方投资大厦SDC智能通信巡更管理系统
EMMC/SD学习小记
Systrace parsing
PyTorch 10. 学习率
网络层重要知识(面试、复试、期末)