Skip to content

Instantly share code, notes, and snippets.

@dorkness-io
Created March 19, 2020 19:19
Show Gist options
  • Save dorkness-io/715e759f36708369abaa8242349fbc50 to your computer and use it in GitHub Desktop.
Save dorkness-io/715e759f36708369abaa8242349fbc50 to your computer and use it in GitHub Desktop.
A brief example that retrieves a count of comments per project. We retrieve the counts for each each issue in a sub-select, and then aggregate by project and sum at the top level. Demonstrates the "count" and "sum" aggregate functions.
select
ss.pname
,sum(ss.comment_count) as sum_comments
from (
select
p.pname
,p.pkey || '-' || ji.issuenum AS issue_key
,count(distinct ja.id) as comment_count
from jiraissue ji
join project p
on ji.project = p.id
join jiraaction ja
on ji.id = ja.issueid
and actiontype = 'comment'
group by 1,2
) ss
group by 1
order by sum_comments desc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment