当前位置:网站首页>[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;
边栏推荐
- Web architecture design process
- STM32按键状态机2——状态简化与增加长按功能
- 苹果cms V10模板/MXone Pro自适应影视电影网站模板
- Add salt and pepper noise or Gaussian noise to the picture
- 【SQL实战】一条SQL统计全国各地疫情分布情况
- Message queuing: how to ensure that messages are not lost
- TCC of distributed transaction solutions
- What are the common message queues?
- 一个简单的代数问题的求解
- 如何提高网站权重
猜你喜欢
What are the common message queues?
Reading notes of Clickhouse principle analysis and Application Practice (6)
目标检测中的BBox 回归损失函数-L2,smooth L1,IoU,GIoU,DIoU,CIoU,Focal-EIoU,Alpha-IoU,SIoU
Get the way to optimize the one-stop worktable of customer service
PTA ladder game exercise set l2-004 search tree judgment
数据中心为什么需要一套基础设施可视化管理系统
数字IC面试总结(大厂面试经验分享)
如何提高网站权重
SQL query: subtract the previous row from the next row and make corresponding calculations
JVM the truth you need to know
随机推荐
linear regression
Realize GDB remote debugging function between different network segments
Industrial Finance 3.0: financial technology of "dredging blood vessels"
Flask1.1.4 Werkzeug1.0.1 源码分析:启动流程
[shell] clean up nohup Out file
Question 102: sequence traversal of binary tree
Data storage 3
[daily training -- Tencent selected 50] 292 Nim games
Simple case of SSM framework
2pc of distributed transaction solution
Harmonyos practice - Introduction to development, analysis of atomized services
Web Authentication API兼容版本信息
牙齿干细胞的存储问题(未完待续)
毕业之后才知道的——知网查重原理以及降重举例
Why does the data center need a set of infrastructure visual management system
@pathvariable 和 @Requestparam的详细区别
MySQL-CentOS7通过YUM安装MySQL
make makefile cmake qmake都是什么,有什么区别?
"Multimodal" concept
PTA 天梯赛练习题集 L2-002 链表去重