当前位置:网站首页>MySQL queries the quantity of each month and the year-on-year and month on month data of each month
MySQL queries the quantity of each month and the year-on-year and month on month data of each month
2022-06-13 00:36:00 【Flying husky】
explain : a_query A table is an empty table
# Query the monthly number of cases reported this year , And the year-on-year and month on month data of cases reported every month
SELECT
monthData.months AS ' month ',
monthData.thisMonth AS ' Number of months ',
IFNULL( CONVERT( ( (monthData.thisMonth - monthData.lastYearThisMonth) / monthData.lastYearThisMonth *100), DECIMAL(10,2) ), 0) AS ' Year on year ',
IFNULL( CONVERT( ( (monthData.thisMonth - monthData.lastMonth) / monthData.lastMonth *100), DECIMAL(10,2) ), 0) AS ' Chain ratio '
FROM(
SELECT
monthTable.months AS months,
(
SELECT
COUNT(id) AS tCount
FROM
case_report
WHERE
is_delete = 0 AND DATE_FORMAT(case_report_time, '%Y-%m') = monthTable.months AND case_area_code LIKE('150201%')
) AS thisMonth,
(
SELECT
COUNT(id) AS tCount
FROM
case_report
WHERE
is_delete = 0 AND PERIOD_DIFF(DATE_FORMAT(STR_TO_DATE(CONCAT(monthTable.months,'-01'),"%Y-%m-%d"), '%Y%m' ), DATE_FORMAT(case_report_time, '%Y-%m' )) = 1
AND case_area_code LIKE('150201%')
) AS lastMonth,
(
SELECT
COUNT(id) AS tCount
FROM
case_report
WHERE
DATE_FORMAT(case_report_time, '%Y%m') = DATE_FORMAT(DATE_SUB(STR_TO_DATE(CONCAT(monthTable.months,'-01'),"%Y-%m-%d") ,INTERVAL 1 YEAR), '%Y%m')
AND case_area_code LIKE('150201%')
) AS lastYearThisMonth,
(
SELECT
COUNT(id) AS tCount
FROM
case_report
WHERE
case_area_code LIKE('150201%')
) AS totalData
FROM (SELECT
CONCAT('2022-', LPAD(id, 2, '0')) AS months
FROM
a_query
ORDER BY
id
LIMIT 12
) monthTable
) monthData
边栏推荐
- Kali system -- fierce of DNS collection and analysis
- How to quickly query the mobile phone number home and operator
- Buuctf's babysql[geek challenge 2019]
- Packaging and uplink of btcd transaction process (III)
- Some basic design knowledge
- Binary search the specified number of numbers in the array binary advanced
- [vscode]todo tree a to-do plug-in
- APISpace 空号检测API接口 免费好用
- ucore lab2
- Explain bio, NiO, AIO in detail
猜你喜欢
Programming training 1
浏览器缓存的执行流程
[ciscn2019 North China Day2 web1]hack world --buuctf
分公司能与员工签劳动合同么
[MRCTF2020]Ez_bypass --BUUCTF
也许尘埃落地,我们才能想清楚互联网的本质
antdPro - ProTable 实现两个选择框联动效果
Transaction creation of btcd transaction process (I)
Kali system -- dnsrecon for DNS collection and analysis
Some basic design knowledge
随机推荐
Kalix system - use of information collection gadgets
Lambda expression
Daily buckle exercise - conclusion
Make the tasks in the scheduled task XXL job flexible
Also on STM32 using dma+ serial port to obtain variable length data
A simple deadlock example
Real time preview of PHP in browser by vscade
[MRCTF2020]Ez_ bypass --BUUCTF
What are the conditions of index invalidation?
What are the levels of safety accidents
杂记:intel11代和12代移动版支持原生Thunderbolt4接口,桌面版不支持
Generate two-dimensional code in Delphi
63. different paths II
63. 不同路径 II
Basics of network security (1)
Using com0com/com2tcp to realize TCP to serial port (win10)
为什么磁盘分区的时候,第一个分区前面总有一段空间(63或者2048个扇区)
Several interview questions in TCP three grips and four swings
Stack overflow learning summary
Easyexcel read excel simple demo