当前位置:网站首页>[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;
边栏推荐
- 数据中心为什么需要一套基础设施可视化管理系统
- 三级菜单数据实现,实现嵌套三级菜单数据
- [云原生]微服务架构是什么?
- make makefile cmake qmake都是什么,有什么区别?
- 搞懂fastjson 对泛型的反序列化原理
- 老板总问我进展,是不信任我吗?(你觉得呢)
- Mac version PHP installed Xdebug environment (M1 version)
- pytorch_ 01 automatic derivation mechanism
- PTA 天梯赛练习题集 L2-003 月饼 测试点2,测试点3分析
- 目标检测中的损失函数与正负样本分配:RetinaNet与Focal loss
猜你喜欢
目标检测中的损失函数与正负样本分配:RetinaNet与Focal loss
如果不知道这4种缓存模式,敢说懂缓存吗?
Question 102: sequence traversal of binary tree
[InstallShield] Introduction
深度聚类:将深度表示学习和聚类联合优化
PowerPivot - DAX (function)
The 2022 China low / no code Market Research and model selection evaluation report was released
SAP Spartacus checkout 流程的扩展(extend)实现介绍
EMMC打印cqhci: timeout for tag 10提示分析与解决
Forkjoin is the most comprehensive and detailed explanation (from principle design to use diagram)
随机推荐
目标检测中的BBox 回归损失函数-L2,smooth L1,IoU,GIoU,DIoU,CIoU,Focal-EIoU,Alpha-IoU,SIoU
Flask1.1.4 Werkzeug1.0.1 源碼分析:啟動流程
I didn't know it until I graduated -- the principle of HowNet duplication check and examples of weight reduction
C. colonne Swapping [tri + Simulation]
SQL query: subtract the previous row from the next row and make corresponding calculations
JVM the truth you need to know
Classic questions about data storage
盘点国内有哪些EDA公司?
Flinksql 读写pgsql
EMMC打印cqhci: timeout for tag 10提示分析与解决
[shell] clean up nohup Out file
力扣102题:二叉树的层序遍历
Question 102: sequence traversal of binary tree
[daily training -- Tencent selected 50] 235 Nearest common ancestor of binary search tree
PTA 天梯赛练习题集 L2-003 月饼 测试点2,测试点3分析
如果不知道这4种缓存模式,敢说懂缓存吗?
ForkJoin最全详解(从原理设计到使用图解)
Add salt and pepper noise or Gaussian noise to the picture
Detailed explanation of platform device driver architecture in driver development
async / await