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

推荐订阅源

美团技术团队
罗磊的独立博客
SecWiki News
SecWiki News
The Register - Security
The Register - Security
The GitHub Blog
The GitHub Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
S
Schneier on Security
IT之家
IT之家
博客园 - 聂微东
T
The Exploit Database - CXSecurity.com
Recorded Future
Recorded Future
大猫的无限游戏
大猫的无限游戏
Know Your Adversary
Know Your Adversary
Latest news
Latest news
Vercel News
Vercel News
G
GRAHAM CLULEY
D
DataBreaches.Net
D
Darknet – Hacking Tools, Hacker News & Cyber Security
S
SegmentFault 最新的问题
博客园_首页
雷峰网
雷峰网
T
Tenable Blog
Spread Privacy
Spread Privacy
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
酷 壳 – CoolShell
酷 壳 – CoolShell
Cisco Talos Blog
Cisco Talos Blog
V
Visual Studio Blog
J
Java Code Geeks
博客园 - Franky
The Cloudflare Blog
Apple Machine Learning Research
Apple Machine Learning Research
C
CERT Recently Published Vulnerability Notes
T
Threatpost
Google DeepMind News
Google DeepMind News
F
Fortinet All Blogs
P
Privacy International News Feed
T
Threat Research - Cisco Blogs
T
The Blog of Author Tim Ferriss
V
Vulnerabilities – Threatpost
Recent Announcements
Recent Announcements
Blog — PlanetScale
Blog — PlanetScale
Security Latest
Security Latest
U
Unit 42
M
MIT News - Artificial intelligence
Y
Y Combinator Blog
K
Kaspersky official blog
有赞技术团队
有赞技术团队
B
Blog
腾讯CDC

博客园 - 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