gpt4 book ai didi

sql - 如何选择表格中前 95% 的行

转载 作者:行者123 更新时间:2023-11-29 12:24:05 27 4
gpt4 key购买 nike

我想根据表数据创建性能报告。

我不知道表中有多少行,我希望根据某些 where 条件获得前 95%(百分比)的行。

表结构-

列名称 - txid、start_time、end_time

对于我的绩效报告,我需要获取结束时间 - 开始时间的平均值。 (end_time - start_time) 的常用值范围为 100 毫秒到 1 秒。然而,由于某些或其他技术错误,很少有事务(少于 2%)花费大约 100-2K 秒。我想避免这些行以获得公平的平均报告。在我的报告中包含这些行引起了极大的关注。

最佳答案

您可以使用子查询。我会选择 row_number()count(*),尽管其他窗口函数如 ntile()percentile_cont( )percentile_disc() 可用于此目的:

select t.*
from (select t.*,
row_number() over (order by <ordering col>) as seqnum,
count(*) over () as cnt
from t
where . . .
) t
where seqnum <= 0.95 * cnt;

关于sql - 如何选择表格中前 95% 的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51211931/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com