惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
S
Securelist
MyScale Blog
MyScale Blog
Jina AI
Jina AI
罗磊的独立博客
The Cloudflare Blog
美团技术团队
博客园 - 叶小钗
阮一峰的网络日志
阮一峰的网络日志
博客园 - 三生石上(FineUI控件)
月光博客
月光博客
雷峰网
雷峰网
小众软件
小众软件
aimingoo的专栏
aimingoo的专栏
大猫的无限游戏
大猫的无限游戏
博客园 - Franky
博客园 - 聂微东
Y
Y Combinator Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
MongoDB | Blog
MongoDB | Blog
T
Tailwind CSS Blog
Attack and Defense Labs
Attack and Defense Labs
博客园_首页
Latest news
Latest news
Apple Machine Learning Research
Apple Machine Learning Research
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The Hacker News
The Hacker News
G
GRAHAM CLULEY
Simon Willison's Weblog
Simon Willison's Weblog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
U
Unit 42
D
Docker
Webroot Blog
Webroot Blog
N
Netflix TechBlog - Medium
T
Tor Project blog
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LINUX DO - 最新话题
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
The Last Watchdog
The Last Watchdog
B
Blog
Recent Announcements
Recent Announcements
GbyAI
GbyAI
Microsoft Azure Blog
Microsoft Azure Blog
Security Latest
Security Latest
V2EX - 技术
V2EX - 技术
N
News | PayPal Newsroom
Microsoft Security Blog
Microsoft Security Blog

博客园 - chenzechao

抓取 DNS 解析记录 router iStoreOS mysql starrocks json处理 json遍历数组所有元素 git复制指定提交到其他分支 secureCrt标签页固定 mac键盘 vs code settings.json 拉链表匹配筛选日期区间 StarRocks中CTE报错 shell 循环遍历的详细用法 shell变量带默认值配置 cursor自动执行 JDK17生成JRE环境 Alt+Tab切换窗口时不包括网页窗口 mysql变量使用 maven工程改版本号,支持多模块一次性修改 SQL自定义排序 IDEA常用快捷键 Linux环境使用上下方向键无法查看history历史记录问题解决方法 博文阅读密码验证 - 博客园 linux设置http proxy flask框架在本机可访问,而其它机子访问不了
mysql取中位数、p80、p90
chenzechao · 2025-07-14 · via 博客园 - chenzechao
select
     api_path
    ,avg(time ) as time_avg
    ,max(case when rn = cast(cn * 0.5 as UNSIGNED) then time end) as time_p50
    ,max(case when rn = cast(cn * 0.8 as UNSIGNED) then time end) as time_p80
    ,max(case when rn = cast(cn * 0.9 as UNSIGNED) then time end) as time_p90
    ,max(case when rn = cast(cn * 1.0 as UNSIGNED) then time end) as time_p100
from (
    select
         ROW_NUMBER() over(partition by t1.api_path order by time) as rn
        ,count(1) over(partition by t1.api_path )      as cn
        ,t1.biz_dt
        ,t1.api_path
        ,t1.time
    from api_log t1
) t2
group by
    api_path
order by time_p50 desc
;
select 
     t1.api_path
    ,t1.api_name
    ,t1.cnt
    ,t1.duration_avg
    ,t1.duration_min
    ,t1.duration_max
    ,t2.time_p50
    ,t2.time_p80
    ,t2.time_p90
    ,t2.time_p100
    ,row_number() over(order by t2.time_p90 desc) as rn
from (
    SELECT 
         api_path
        ,api_name
        ,count(1) as cnt
        ,avg(duration_prd) as duration_avg
        ,min(duration_prd) as duration_min
        ,max(duration_prd) as duration_max
    FROM api_request_config_performance
    group by 
         api_path
        ,api_name
    order by 
        duration_avg desc
) t1
left join (
    select
         api_path
        ,avg(duration_prd )                                                   as time_avg
        ,max(case when rn = cast(cn * 0.5 as UNSIGNED) then duration_prd end) as time_p50
        ,max(case when rn = cast(cn * 0.8 as UNSIGNED) then duration_prd end) as time_p80
        ,max(case when rn = cast(cn * 0.9 as UNSIGNED) then duration_prd end) as time_p90
        ,max(case when rn = cast(cn * 1.0 as UNSIGNED) then duration_prd end) as time_p100
    from (
        select
             ROW_NUMBER() over(partition by t1.api_path order by duration_prd) as rn
            ,count(1) over(partition by t1.api_path )      as cn
            ,t1.api_path
            ,t1.duration_prd
        from api_request_config_performance t1
    ) t2
    group by
        api_path
) t2
    on t1.api_path = t2.api_path