当前位置:网站首页>【SQL实战】一条SQL统计全国各地疫情分布情况
【SQL实战】一条SQL统计全国各地疫情分布情况
2022-07-07 00:35:00 【51CTO】

-- 疫情表,三个字段:城市/地区 省份 当前确诊人数
DROP TABLE IF EXISTS yiqing;
CREATE TABLE `datacenter`.`yiqing`(
`city` VARCHAR(32) COMMENT '城市/地区',
`province` VARCHAR(32) COMMENT '省份',
`current` INT COMMENT '当前确认人数'
)
COMMENT='疫情信息表';
INSERT INTO yiqing
SELECT '津南区', '天津', 217 UNION ALL
SELECT '安阳', '陕西', 110 UNION ALL
SELECT '西安', '陕西', 1385 UNION ALL
SELECT '咸阳', '河南', 10 UNION ALL
SELECT '郑州', '河南', 138 UNION ALL
SELECT '南阳', '河南', 95 UNION ALL
SELECT '呼伦贝尔', '内蒙古', 5 UNION ALL
SELECT '宁波', '浙江', 55 UNION ALL
SELECT '开封', '河南', 5 UNION ALL
SELECT '金华', '浙江', 3 UNION ALL
SELECT '防城港', '广西', 2 UNION ALL
SELECT '中山', '广东', 51 UNION ALL
SELECT '大连', '辽宁', 3 ;
SELECT * FROM yiqing ORDER BY 2,1;

-- §§§【统计全国疫情分布情况 结果列:省份、严重程度级别、累计确诊人数】
SELECT province AS '省份'
, CASE WHEN SUM(current)>=100 THEN 'Level1' WHEN SUM(current)<100 AND SUM(current)>=50 THEN 'Level2' ELSE 'Levy3' END AS '严重程度'
, SUM(current) AS '累计确认人数'
FROM yiqing
GROUP BY province
ORDER BY 3 DESC;

-- §§§【统计各省份疫情分布情况 结果列:省份、疫情风险等级、城市地区数、当前确诊数。例如:河南省有3个高风险城市,确诊人数总计300人】
SELECT province AS '省份'
, CASE WHEN current>=100 THEN '高'
WHEN current>=50 AND current<100 THEN '中'
ELSE '低' END AS '疫情风险等级'
, COUNT(1) AS '城市地区数'
, SUM(current) AS '当前确诊数'
FROM yiqing
GROUP BY province, CASE WHEN current>=100 THEN '高'
WHEN current>=50 AND current<100 THEN '中'
ELSE '低' END
ORDER BY 1, CASE 疫情风险等级 WHEN '高' THEN 1 WHEN '中' THEN 2 ELSE 3 END;

边栏推荐
猜你喜欢

驱动开发中platform设备驱动架构详解

产业金融3.0:“疏通血管”的金融科技

An example of multi module collaboration based on NCF

Web Authentication API兼容版本信息

WEB架构设计过程

What is dependency injection (DI)

Introduction to distributed transactions
![[reading of the paper] a multi branch hybrid transformer network for channel terminal cell segmentation](/img/f6/cd307c03ea723e1fb6a0011b37d3ef.png)
[reading of the paper] a multi branch hybrid transformer network for channel terminal cell segmentation

Common skills and understanding of SQL optimization

SAP ABAP BDC(批量数据通信)-018
随机推荐
软件测试面试技巧
【已解决】记一次EasyExcel的报错【读取xls文件时全表读不报错,指定sheet名读取报错】
980. 不同路径 III DFS
What is make makefile cmake qmake and what is the difference?
Flinksql read / write PgSQL
架构设计的五个核心要素
C#可空类型
Determine whether the file is a DICOM file
Input of native applet switches between text and password types
Dynamic memory management
WEB架构设计过程
Message queuing: how to ensure that messages are not lost
C nullable type
The 2022 China low / no code Market Research and model selection evaluation report was released
AI face editor makes Lena smile
Web architecture design process
[solved] record an error in easyexcel [when reading the XLS file, no error will be reported when reading the whole table, and an error will be reported when reading the specified sheet name]
Three level menu data implementation, nested three-level menu data
What are the common message queues?
分布式全局ID生成方案