You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

按多列分组求和、计数、最大值,及按sprint与sprintweek统计缺陷需求

嘿,我来帮你搞定这个需求!根据你说的按sprint和sprintweek统计缺陷上报总数,还要找出顶级缺陷上报人,我分几种常用工具给你具体方案:

1. SQL实现方案

假设你的数据表名为defects,包含字段:sprint(迭代周期)、sprintweek(迭代内周数)、defects_reported(上报缺陷数)、reporter(缺陷上报人)。如果你的字段名不一样,对应替换就行。

1.1 按Sprint+SprintWeek统计缺陷总数

用分组聚合就能轻松拿到每周的总缺陷数:

SELECT
    sprint,
    sprintweek,
    SUM(defects_reported) AS total_defects_reported
FROM defects
GROUP BY sprint, sprintweek
ORDER BY sprint, sprintweek;

1.2 找出顶级缺陷上报人

全局顶级上报人(所有周期内上报最多的)

SELECT
    reporter,
    SUM(defects_reported) AS total_reported
FROM defects
GROUP BY reporter
ORDER BY total_reported DESC
LIMIT 1; -- 要前N个就把1改成N,比如前3就写LIMIT 3

按每个Sprint+SprintWeek的顶级上报人

用窗口函数可以精准筛选出每个周的上报冠军:

WITH weekly_reporter_stats AS (
    SELECT
        sprint,
        sprintweek,
        reporter,
        SUM(defects_reported) AS total_reported,
        RANK() OVER (PARTITION BY sprint, sprintweek ORDER BY SUM(defects_reported) DESC) AS report_rank
    FROM defects
    GROUP BY sprint, sprintweek, reporter
)
SELECT
    sprint,
    sprintweek,
    reporter AS top_reporter,
    total_reported
FROM weekly_reporter_stats
WHERE report_rank = 1;
2. Python Pandas实现方案

假设你已经把数据读入了DataFramedf:

2.1 按Sprint+SprintWeek统计总数

# 分组求和并重置索引,让结果更规整
weekly_total = df.groupby(['sprint', 'sprintweek'])['defects_reported'].sum().reset_index()
weekly_total.columns = ['sprint', 'sprintweek', 'total_defects_reported']
print(weekly_total)

2.2 找出顶级上报人

全局顶级上报人

top_global = df.groupby('reporter')['defects_reported'].sum().sort_values(ascending=False).head(1)
print("全局顶级缺陷上报人:")
print(top_global)

按每个Sprint+SprintWeek的顶级上报人

# 先计算每个上报人在每周的上报总数
weekly_reporter_total = df.groupby(['sprint', 'sprintweek', 'reporter'])['defects_reported'].sum().reset_index()
# 筛选出每组(Sprint+Week)里上报数最大的记录
top_weekly = weekly_reporter_total.loc[weekly_reporter_total.groupby(['sprint', 'sprintweek'])['defects_reported'].idxmax()]
top_weekly.columns = ['sprint', 'sprintweek', 'top_reporter', 'total_reported']
print(top_weekly)
3. Excel实现方案

如果习惯用Excel处理:

3.1 按Sprint+SprintWeek统计总数

  1. 选中你的数据区域,点击「插入」→「数据透视表」
  2. 把sprint和sprintweek拖到「行」区域,defects_reported拖到「值」区域,右键值区域选择「值字段设置」,把汇总方式改成「求和」

3.2 找出顶级上报人

全局顶级

同样用数据透视表:把reporter拖到「行」,defects_reported拖到「值」(求和),然后点击值列的排序按钮,选择「降序」,最上方的就是全局顶级上报人。

按周的顶级

可以用Power Query:选中数据后点击「数据」→「从表格/区域」,进入Power Query编辑器后,依次点击「分组依据」→ 分组列选sprint和sprintweek,新增列选reporter和defects_reported(求和),然后再分组筛选每组的最大值对应的上报人即可。

内容的提问来源于stack exchange,提问作者ItsMeGokul

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 04:32:49