我正在尝试从JIRA应用程序查询多个表,我们正在运行Oracle DB。我试图做的是写一个单一的查询,可以总计用户名的数量和它看到的单个用户名的次数。我可以在每个统计基础上做这个(评论,问题历史等等),但还没有找到一种能够以有意义的方式组合我的查询的方法....
-- Comment total by user query:
select author, count(actiontype) as total
from jiraaction
group by author
order by total desc;
-- Jira issues reported by user query:
select reporter, count(reporter) as total
from jiraissue
group by reporter
Order by total desc
答案 0 :(得分:0)
使用union all
并重新组合:
select author, sum(authors) as NumAuthors, sum(Reporters) as NumReporters,
(sum(authors) + sum(reporters) ) as Total
from ((select author, count(actiontype) as authors, 0 as reporters
from jiraaction
group by author
) union all
(select reporter, 0, count(reporter)
from jiraissue
group by reporter
)
) ar
group by author
Order by total desc;
答案 1 :(得分:0)
您可以使用UNION操作。像这样:
Select a.author, sum(a.total) as total
from (
select author, count(actiontype) as total
from jiraaction
group by author
UNION ALL
select reporter, count(reporter) as total
from jiraissue
group by reporter
) a
order by a.total desc