如何将特定结果集与匹配结果集聚合

How to aggregate a specific set of results with the matching set of results

这里有两个查询的 2 个输出:

输出 1:

duration               | allWorkItems
-----------------------+------
 between 15 and 60 min | 56
 bigger than 60 min    | 39

输出 2:

duration               | finishedWorkItems
-----------------------+------
 between 15 and 60 min | 19
 bigger than 60 min    | 28

现在我想将“finishedWorkItems”除以“allWorkItems”以获得百分比。 所以在简化代码中:

SELECT CASE 
WHEN strftime('%s', end) - strftime('%s', beginning) < 15*60 THEN 'smaller than 15 min'
WHEN  strftime('%s', end) - strftime('%s', beginning) BETWEEN 15*60 AND 60*60 THEN 'between 15 min and 60 min'
ELSE 'more than 60 min' END AS duration,
**(COUNT(task_id WHERE finished = true)/COUNT(task_id)) finishingRate**
FROM 
[..](I think the query would be too long)
GROUP BY 1

我试图通过子查询解决这个问题。但是,这不起作用,而且可读性非常差。 有没有人有解决这个问题的想法?

本例中的结果应该是:

duration               | finishingRate
-----------------------+------
 between 15 and 60 min | 0,33
 bigger than 60 min    | 0,71

join怎么样?

with q1 as (< query 1 here>),
     q2 as (< query 2 here>)
select q1.duration, q2.finishedWorkItems / q1.finishedWorkItems
from q1 join
     q2
     on q1.duration = q2.duration;