当前位置:网站首页>73- find the SQL example during the business peak period (report development class)
73- find the SQL example during the business peak period (report development class)
2022-06-22 21:21:00 【Tiger Liu】
The following business logic code segment was proposed in the technical discussion group :
The business logic of this code is to find 2019 With the largest annual business volume 61 second ( I think the original intention should be 60 second , The code is not rigorous enough ) Interval and business volume .
This business question mainly uses plsql complete , It is a typical programmer's thinking , The execution efficiency is obviously very low , My advice is to press to_char(date_created,'yyyymmdd hh24mi') do group by, Then find the maximum ,sql The writing method is relatively simple , I believe that most developers should be able to simply write .
But the subject added other requirements , It may be necessary to make statistics at different time intervals , such as 15 Second interval ,30 Second interval, etc .
In response to this demand , I give SQL It is written as follows ( With 15 Second interval as an example ):
The title owner made a performance comparison between the two writing methods ,1000 More than a million records , The writing method I provided is time-consuming 125 second , primary plsql It takes time to write 1371 second ( This speed is unacceptable ), Efficiency difference 10 Several times , If the amount of data is large , The difference in efficiency will be even greater , And the optimized sql You can also use parallelism , It can speed up .
The query above , The starting point of the interval is fixed , This kind of writing is not too complicated . If we extend this problem further , For example, check which is continuous in a year 10 The business volume is the highest in days ,sql It is relatively complicated , Here's how I put it :
Here are some uses Analysis function Two small cases of , You can refer to it . meanwhile , Use with Of CTE Writing will make sql The level of is relatively clear , Improve the readability of the code .
If you have a better way of writing , You might as well write it in your message , Let's learn together .
边栏推荐
猜你喜欢

【21. 合并两个有序链表】
![[redis]Redis6的事务操作](/img/50/639867a2fcb92082ea262a8a19bb68.png)
[redis]Redis6的事务操作

Arcgis中las点云数据抽稀

R语言midwest数据集可视化

Numpy learning notes (6) -- sum() function

R 语言 wine 数据集可视化

大势智慧创建倾斜模型和切割单体化

2022 question bank and simulated examination for work license of main principals of hazardous chemical business units
![[redis] profile](/img/1c/05c06d59c9efb5983f877822db333c.png)
[redis] profile

访问成功但抛出异常:Could not find acceptable representation
随机推荐
NumPy学习笔记(六)——sum()函数
[redis]发布与订阅
[redis]配置文件
字节跳动提出轻量级高效新型网络MoCoViT,在分类、检测等CV任务上性能优于GhostNet、MobileNetV3!...
2022团体程序设计天梯赛L1
Moke 6. Load balancing ribbon
las 点云创建网格
[redis]redis6 master-slave replication
Baijia forum Daqin rise (lower part)
Win10 installation net3.5. docx
Redis learning notes
[redis] cluster and common errors
苹果Objective-C源代码
如何使用Feign构造多参数的请求
Easyclick update Gallery
【OR36 链表的回文结构】
Baijia forum Huangdi Neijing (Part I)
R language organdata dataset visualization
访问成功但抛出异常:Could not find acceptable representation
SwiftUI如何模拟视图发光增大的动画效果