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

如何在JIRA JQL查询中使用MAX筛选最大自定义字段值的工单

解决JQL筛选自定义字段最大值工单的问题

JQL本身不支持直接调用聚合函数(如MAX),但可以通过两种方式实现你的需求:

方法一:使用ScriptRunner插件(推荐,适合自动化场景)

如果你的JIRA安装了ScriptRunner插件,可借助aggregateExpression函数直接筛选出cf[12901]为最大值的工单,同时修正原查询仅筛选Defect的问题(加入Story类型):

issueFunction in aggregateExpression("cf[12901] = max(cf[12901])", "project = \"xyz\" AND (cf[10005] is not EMPTY AND cf[10005] in closedSprints()) AND cf[12901] is not EMPTY AND type in (Defect, Story) AND component = \"abc\" AND status = \"Done\" AND (assignee = P3171324 OR assignee = 1 OR assignee = 2)")

该查询逻辑为:先在括号内的基础条件范围内计算cf[12901]的最大值,再返回所有字段值等于该最大值的工单。

方法二:无插件手动实现(适合临时查询)

若未安装ScriptRunner,可分两步操作:

  1. 先执行修正后的基础查询(包含Defect和Story,保留其余所有条件),按cf[12901]降序排序:
project = "xyz" AND (cf[10005] is not EMPTY AND cf[10005] in closedSprints()) AND cf[12901] is not EMPTY AND type in (Defect, Story) AND component = "abc" AND status = "Done" AND (assignee = P3171324 OR assignee = 1 OR assignee = 2) ORDER BY cf[12901] DESC

查看结果列表中首个工单的cf[12901]数值(比如示例中的53)。
2. 在原查询中添加cf[12901] = 最大值的条件,替换为实际获取到的数值:

project = "xyz" AND (cf[10005] is not EMPTY AND cf[10005] in closedSprints()) AND cf[12901] is not EMPTY AND type in (Defect, Story) AND component = "abc" AND status = "Done" AND (assignee = P3171324 OR assignee = 1 OR assignee = 2) AND cf[12901] = 53

即可得到所有该字段值为最大值的工单。

内容的提问来源于stack exchange,提问作者Charles L.

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.28 22:42:49