当前位置:网站首页>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 裸机教程1:GPIO,IOMUX,I2C

项目文件“ ”已被重命名或已不在解决方案中、未能找到与解决方案关联的源代码管理提供程序——两个工程问题

Gather, unsqueeze and other operators when PTH is converted to onnx

美摄科技受邀LVSon2020大会 分享《AI合成虚拟人物的技术框架与挑战》

传输层重要知识(面试,复试,期末)

1.1 pytorch and neural network

Wechat applet uses wxml2canvas plug-in to generate some problem records of pictures

Device Tree 详解

AUTOSAR从入门到精通100讲(五十二)-诊断和通信管理功能单元

pth 转 onnx 时出现的 gather、unsqueeze 等算子
随机推荐
Unable to determine the device handle for GPU 0000:02:00.0: GPU is lost.
AUTOSAR从入门到精通100讲(八十六)-UDS服务基础篇之2F
地铁无线对讲系统
PyTorch 22. PyTorch常用代码段合集
Device Tree 详解
imx6ull-qemu 裸机教程2:USDHC SD卡
SSL / TLS application example
带低压报警的51单片机太阳能充电宝设计与制作(完整代码资料)
AUTOSAR从入门到精通100讲(八十四)-UDS之时间参数总结篇
北峰通信助力湛江市消防支队构建PDT无线通信系统
x86架构初探之8086
AUTOSAR从入门到精通100讲(五十二)-诊断和通信管理功能单元
AUTOSAR从入门到精通100讲(八十一)-AUTOSAR基础篇之FiM
【期刊会议系列】IEEE系列模板下载指南
GIS实战应用案例100篇(五十二)-ArcGIS中用栅格裁剪栅格,如何保持行列数量一致并且对齐?
【点云系列】Multi-view Neural Human Rendering (NHR)
Proteus 8.10安装问题(亲测稳定不闪退!)
【点云系列】Neural Opacity Point Cloud(NOPC)
PyTorch 21. PyTorch中nn.Embedding模块
画 ArcFace 中的 margin 曲线