当前位置:网站首页>SQL exercise question 1
SQL exercise question 1
2022-04-23 12:57:00 【Look at the data at the top of the mountain】
subject
Table name :macro_index_data
Field name :
Data period ( years ) Region code The index code The index type ( growth 、 Total amount ) Index value Data update time
occur_period area_code index_code index_type index_value update_time
explain : The zoning code of Luohu District is 440305000000、GDP The indicator code is gmjj_jjzl_01、 The enumeration values of indicator types are respectively (TB)、 Total amount (JDZ)
problem
Please write out ,2020 year 4 Quarterly GDP The growth rate of has exceeded that of Luohu District. What are the districts in the same period
answer
-- Luohu District 2020 year 4 It's a quarter of GDP growth
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
-- Find the in other areas GDP growth
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
-- Integration function
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;
版权声明
本文为[Look at the data at the top of the mountain]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230615024638.html
边栏推荐
- CGC: contractual graph clustering for community detection and tracking
- 教你快速开发一个 狼人杀微信小程序(附源码)
- If you were a golang interviewer, what questions would you ask?
- Get the punch in record of nailing attendance machine
- World Book Day: I'd like to recommend these books
- Trier les principales utilisations de l'Agent IP réseau
- 云原生KubeSphere部署Redis
- Introducing vant components on demand
- Start mqbroker CMD failure resolution
- php生成json处理中文
猜你喜欢

Image attribute of input: type attribute of fashion cloud learning -h5

Object. The disorder of key value array after keys

Trier les principales utilisations de l'Agent IP réseau

Use source insight to view and edit source code

mysql支持ip访问

Remote access to raspberry pie at home (Part 1)

梳理網絡IP代理的幾大用途

No idle servers? Import OVF image to quickly experience smartx super fusion community version

拥抱机器视觉新蓝海,冀为好望开启数字经济发展新“冀”遇

What are the forms of attack and tampering on the home page of the website
随机推荐
Sort out several uses of network IP agent
BUUCTF WEB [GXYCTF2019]禁止套娃
Huawei cloud MVP email
21 days learning mongodb notes
Synchronously update the newly added and edited data to the list
大家帮我看一下这是啥情况,MySQL5.5的。谢了
Ad20 supplementary note 3 - shortcut key + continuous update
Wonderful review | the sixth issue of "source" - open source economy and industrial investment
SSM framework series - JUnit unit test optimization day2-3
Baserecyclerviewadapterhelper realizes pull-down refresh and pull-up loading
Can I take the CPDA data analyst certificate for 0 foundation
Kubernetes 入門教程
Try the server for one month for free, and attach the tutorial
box-sizing
Go language slicing operation
Aviation core technology sharing | overview of safety characteristics of acm32 MCU
8 websites that should be known for product development to enhance work experience
Record some NPM related problems (messy records)
Plato farm - a game of farm metauniverse with Plato as the goal
leetcode:437. 路径总和 III【dfs 选还是不选?】