This may look like a basic question but I am having serious trouble finding a solution for it. I'm querying the Jira database directly and that works fine. I do have 2 queries that spit out a date that a ticket has transitioned from certain status to another set of statuses. Then I have a second query that checks the same thing for when it changes to DONE. I'm looking to merge these 2 queries into a single one.
Query 1:
SELECT distinct on (i.issuenum) issuenum, to_char(cg.created, 'DD-MON-YYYY') as datemoved, ci.oldvalue, ci.newvalue from changeitem ci
inner join changegroup cg on cg.id = ci.groupid
inner join jiraissue i on i.id = cg.issueid
inner join issuestatus s on s.id = i.issuestatus
inner join project p on p.id = i.project
where ci.oldvalue in ('10400') and ci.newvalue in ('10904', '10504', '3', '10000') and project = 11009 and s.id = '10000'
order by i.issuenum asc
Query 2:
SELECT distinct on (i.issuenum) issuenum, to_char(cg.created, 'DD-MON-YYYY') as datemoved,
filter (where ci.newvalue = '10000', to_char(cg.created, 'DD-MON-YYYY')
ci.oldvalue, ci.newvalue from changeitem ci
inner join changegroup cg on cg.id = ci.groupid
inner join jiraissue i on i.id = cg.issueid
inner join issuestatus s on s.id = i.issuestatus
inner join project p on p.id = i.project
where ci.oldvalue in ('10400') and ci.newvalue in ('10904', '10504', '3', '10000') and project = 11009 and s.id = '10000'
order by i.issuenum asc
As you can see, both queries are identical except for the conditions. I get the 2 outputs and put them side to side to get the output that I need, which is obviously not the right way of doing it. Appreciate any pointers here.
filtershould be used with aggregate or window functions, the opening "(" near "filter" has no closing ")".