我怎样才能从 table 获得 运行 状态?

how can I can running status from my table?

我有一个下面的 table,其中有多行具有相同的 executionid 和不同的状态。如何获取状态为 运行 的行,如果 executionid 与 运行 和完成状态相关联,行将被排除?

下图是示例数据:

预期结果应该是:

简单select:

select * 
  from your_table
 where status = 'running';

这是您可以获得的最基本的 SQL 声明。我建议您获取 SQL 文本,并尝试一些教程。

  • 使用 String_AGG() 将每个执行 ID 的所有状态放入一个列表中
  • 将该列表加入原始数据,然后使用 NOT LIKE 运算符过滤掉结果,如果有案例已完成并且 运行 则它们不会被选中
with all_status as (
Select

execution_id,
STRING_AGG (status,', ') as all_status_per_id
from [table]
)

Select 
data.*,
all_status.all_status_per_id
from [table] as data
left join all_status 
on data.execution_id = all_status.execution_id
where (all_status.all_status_per_id LIKE '%running%' AND all_status.all_status_per_id NOT LIKE '%completed%')
AND status = 'running'