当前位置:网站首页>[SQL practice] a SQL statistics of epidemic distribution across the country
[SQL practice] a SQL statistics of epidemic distribution across the country
2022-07-07 05:56:00 【51CTO】
-- Epidemic situation table , Three fields : City / region Province Current confirmed number
DROP TABLE IF EXISTS yiqing;
CREATE TABLE `datacenter`.`yiqing`(
`city` VARCHAR(32) COMMENT ' City / region ',
`province` VARCHAR(32) COMMENT ' Province ',
`current` INT COMMENT ' Current confirmed number '
)
COMMENT=' Epidemic information table ';
INSERT INTO yiqing
SELECT ' Jinnan District ', ' tianjin ', 217 UNION ALL
SELECT ' anyang ', ' shaanxi ', 110 UNION ALL
SELECT ' Xi'an ', ' shaanxi ', 1385 UNION ALL
SELECT ' xianyang ', ' Henan ', 10 UNION ALL
SELECT ' zhengzhou ', ' Henan ', 138 UNION ALL
SELECT ' Nanyang ', ' Henan ', 95 UNION ALL
SELECT ' The hulunbuir ', ' Inner Mongolia ', 5 UNION ALL
SELECT ' ningbo ', ' Zhejiang ', 55 UNION ALL
SELECT ' kaifeng ', ' Henan ', 5 UNION ALL
SELECT ' jinhua ', ' Zhejiang ', 3 UNION ALL
SELECT ' port of fangcheng ', ' guangxi ', 2 UNION ALL
SELECT ' zhongshan ', ' guangdong ', 51 UNION ALL
SELECT ' dalian ', ' liaoning ', 3 ;
SELECT * FROM yiqing ORDER BY 2,1;
-- §§§【 Statistics on the distribution of epidemic situation in the country Result column : Province 、 Severity level 、 Cumulative number of confirmed cases 】
SELECT province AS ' Province '
, CASE WHEN SUM(current)>=100 THEN 'Level1' WHEN SUM(current)<100 AND SUM(current)>=50 THEN 'Level2' ELSE 'Levy3' END AS ' severity '
, SUM(current) AS ' Cumulative confirmed number '
FROM yiqing
GROUP BY province
ORDER BY 3 DESC;
-- §§§【 Statistics on the distribution of epidemic situation in various provinces Result column : Province 、 Epidemic risk level 、 Number of urban areas 、 Current confirmed number . for example : Henan Province has 3 A high-risk city , The total number of confirmed cases 300 people 】
SELECT province AS ' Province '
, CASE WHEN current>=100 THEN ' high '
WHEN current>=50 AND current<100 THEN ' in '
ELSE ' low ' END AS ' Epidemic risk level '
, COUNT(1) AS ' Number of urban areas '
, SUM(current) AS ' Current confirmed number '
FROM yiqing
GROUP BY province, CASE WHEN current>=100 THEN ' high '
WHEN current>=50 AND current<100 THEN ' in '
ELSE ' low ' END
ORDER BY 1, CASE Epidemic risk level WHEN ' high ' THEN 1 WHEN ' in ' THEN 2 ELSE 3 END;
边栏推荐
- 老板总问我进展,是不信任我吗?(你觉得呢)
- 线性回归
- Industrial Finance 3.0: financial technology of "dredging blood vessels"
- [daily training -- Tencent selected 50] 292 Nim games
- SAP ABAP BDC (batch data communication) -018
- Flask1.1.4 Werkzeug1.0.1 源码分析:启动流程
- SAP ABAP BDC(批量数据通信)-018
- 集群、分布式、微服務的區別和介紹
- TCC of distributed transaction solutions
- Web Authentication API兼容版本信息
猜你喜欢
ForkJoin最全详解(从原理设计到使用图解)
一个简单的代数问题的求解
毕业之后才知道的——知网查重原理以及降重举例
PTA ladder game exercise set l2-004 search tree judgment
Web Authentication API兼容版本信息
集群、分布式、微服務的區別和介紹
[daily training -- Tencent selected 50] 235 Nearest common ancestor of binary search tree
PTA 天梯赛练习题集 L2-004 搜索树判断
苹果cms V10模板/MXone Pro自适应影视电影网站模板
CTFshow--常用姿势
随机推荐
Harmonyos practice - Introduction to development, analysis of atomized services
C nullable type
Go语学习笔记 - gorm使用 - gorm处理错误 | Web框架Gin(十)
win配置pm2开机自启node项目
Interview questions and salary and welfare of Shanghai byte
毕业之后才知道的——知网查重原理以及降重举例
Go 語言的 Context 詳解
线性回归
Flinksql read / write PgSQL
如果不知道这4种缓存模式,敢说懂缓存吗?
What is dependency injection (DI)
How to get free traffic in pinduoduo new store and what links need to be optimized in order to effectively improve the free traffic in the store
Input of native applet switches between text and password types
Go language learning notes - Gorm use - Gorm processing errors | web framework gin (10)
SAP Spartacus checkout 流程的扩展(extend)实现介绍
Hcip seventh operation
PTA TIANTI game exercise set l2-003 moon cake test point 2, test point 3 Analysis
yarn入门(一篇就够了)
SQLSTATE[HY000][1130] Host ‘host. docker. internal‘ is not allowed to connect to this MySQL server
SAP ABAP BDC (batch data communication) -018