如何在 test_item 行上获取 project_id 和/或 project_name
How to get project_id and / or project_name on the test_item row
我正在尝试针对 reportportal v5 的 postgresql 数据库编写 sql,但发现没有明确的方法来获取 project_id [以及扩展 project_name]与 test_item.
在同一行
我最初写了这个查询
select
tir.result_id,
ti.start_time,
tir.end_time,
tir.duration,
ti.item_id as test_item_id,
cq.issue_name,
STRING_AGG(l.log_message, '\t') as log_message
from test_item_results tir
left join test_item ti
on tir.result_id = ti.item_id
left join issue i
on tir.result_id = i.issue_id
join (select "name", project_type, issue_type_id, issue_group_id, issue_name from project p
join issue_type_project itp
on p.id = itp.project_id
join issue_type it
on itp.issue_type_id = it.id
where project_type = 'INTERNAL') cq
on i.issue_type = cq.issue_type_id
left join log l
on tir.result_id = l.item_id
where tir.status = 'FAILED'
and type IN ('STEP')
and cq.issue_name <> 'To Investigate'
and cq.issue_name in ('Product Bug', 'Automation Bug', 'System Issue', 'No Defect')
and l.log_message is not NULL
group by tir.result_id, ti.start_time, tir.end_time, ti.item_id, tir.result_id, i.issue_id, cq.issue_name
order by ti.start_time desc
但是,固定故障类型:产品错误、自动化错误、系统问题和无缺陷适用于所有项目(个人或内部)。此查询然后导致相同的 test_item 并且其结果在所有项目中重复。
然后我查看了数据库图表,注意到有这些空模板 table:pattern_template_test_item
和 pattern_template
。我在弄清楚如何使用这些方面没有取得任何成功。我看到 project
table 与 pattern_template
有关系,pattern_template
与 pattern_template_test_item
有关系 test_item
.
有人知道如何写这个 sql 吗?我的最终目标是在没有重复的情况下获得我从查询中看到的输出。另外,我可以不在这里使用distinct,因为我需要测试和结果所属的实际项目。
这只是从 test_item
到 launch
到 project
的几个连接:
SELECT ti.*
, pr.name
FROM test_item AS ti
JOIN launch AS la
ON ti.launch_id = la.id
JOIN project AS pr
ON la.project_id = pr.id
;
只需扩展您当前的 SQL 即可根据需要添加这些额外的联接。
但是请注意,您在加入 test_item
时使用了 LEFT JOIN
。
这表明您可能不会在每一行中都有匹配的 test_item
。在这些情况下,您需要决定要做什么。如果你想用空值而不是项目名称保留这些结果,请使用外部联接。
像这样:
SELECT ti.*
, COALESCE(pr.name, 'NoProject') AS proj_name
FROM test_item AS ti
LEFT JOIN launch AS la
ON ti.launch_id = la.id
LEFT JOIN project AS pr
ON la.project_id = pr.id
;
我正在尝试针对 reportportal v5 的 postgresql 数据库编写 sql,但发现没有明确的方法来获取 project_id [以及扩展 project_name]与 test_item.
在同一行我最初写了这个查询
select
tir.result_id,
ti.start_time,
tir.end_time,
tir.duration,
ti.item_id as test_item_id,
cq.issue_name,
STRING_AGG(l.log_message, '\t') as log_message
from test_item_results tir
left join test_item ti
on tir.result_id = ti.item_id
left join issue i
on tir.result_id = i.issue_id
join (select "name", project_type, issue_type_id, issue_group_id, issue_name from project p
join issue_type_project itp
on p.id = itp.project_id
join issue_type it
on itp.issue_type_id = it.id
where project_type = 'INTERNAL') cq
on i.issue_type = cq.issue_type_id
left join log l
on tir.result_id = l.item_id
where tir.status = 'FAILED'
and type IN ('STEP')
and cq.issue_name <> 'To Investigate'
and cq.issue_name in ('Product Bug', 'Automation Bug', 'System Issue', 'No Defect')
and l.log_message is not NULL
group by tir.result_id, ti.start_time, tir.end_time, ti.item_id, tir.result_id, i.issue_id, cq.issue_name
order by ti.start_time desc
但是,固定故障类型:产品错误、自动化错误、系统问题和无缺陷适用于所有项目(个人或内部)。此查询然后导致相同的 test_item 并且其结果在所有项目中重复。
然后我查看了数据库图表,注意到有这些空模板 table:pattern_template_test_item
和 pattern_template
。我在弄清楚如何使用这些方面没有取得任何成功。我看到 project
table 与 pattern_template
有关系,pattern_template
与 pattern_template_test_item
有关系 test_item
.
有人知道如何写这个 sql 吗?我的最终目标是在没有重复的情况下获得我从查询中看到的输出。另外,我可以不在这里使用distinct,因为我需要测试和结果所属的实际项目。
这只是从 test_item
到 launch
到 project
的几个连接:
SELECT ti.*
, pr.name
FROM test_item AS ti
JOIN launch AS la
ON ti.launch_id = la.id
JOIN project AS pr
ON la.project_id = pr.id
;
只需扩展您当前的 SQL 即可根据需要添加这些额外的联接。
但是请注意,您在加入 test_item
时使用了 LEFT JOIN
。
这表明您可能不会在每一行中都有匹配的 test_item
。在这些情况下,您需要决定要做什么。如果你想用空值而不是项目名称保留这些结果,请使用外部联接。
像这样:
SELECT ti.*
, COALESCE(pr.name, 'NoProject') AS proj_name
FROM test_item AS ti
LEFT JOIN launch AS la
ON ti.launch_id = la.id
LEFT JOIN project AS pr
ON la.project_id = pr.id
;