Home > OS >  Use DENSE_RANK() with left outer join
Use DENSE_RANK() with left outer join

Time:12-07

I'm using the above code to perform a left join on jira.releases table:

SELECT b.*,c.releasedate from digitalpfatforms.issues_braze b
Left join jira.releases c
On b.version_id=c.versionid

With this I get the following intended output:

issueid sprintid sprintenddate version_id releasedate
1945 85 20/11/2021 45699 25/11/2021
1836 90 01/12/2021 54555 05/12/2021
1836 90 01/12/2021 54555 05/12/2021
2000 55 10/11/2021 56777 15/11/2021
2000 55 10/11/2021 56777 15/11/2021
2000 55 10/11/2021 56777 15/11/2021

Out of this output I need to calculate 2 dense_rank(). One over sprintenddate:

DENSE_RANK() OVER(ORDER BY b.sprintenddate DESC) AS "rank_sprint"

and the other over releasedate:

DENSE_RANK() OVER(ORDER BY c.releasedate DESC) AS "rank_release"

My intended output is the:

issueid sprintid sprintenddate version_id releasedate rank_sprint rank_release
1945 85 20/11/2021 45699 25/11/2021 2 2
1836 90 01/12/2021 54555 05/12/2021 1 1
1836 90 01/12/2021 54555 05/12/2021 1 1
2000 55 10/11/2021 56777 15/11/2021 3 3
2000 55 10/11/2021 56777 15/11/2021 3 3
2000 55 10/11/2021 56777 15/11/2021 3 3

Can anyone help me on how to put together the SQL query so that it perfoms a join and calculates the mentioned dense_rank?

Thank you

CodePudding user response:

Looks like you did all of the work already. Add the pieces together and it will work.

SELECT b.*,
c.releasedate,
DENSE_RANK() OVER(ORDER BY b.sprintenddate DESC) AS "rank_sprint",
DENSE_RANK() OVER(ORDER BY c.releasedate DESC) AS "rank_release"
from digitalpfatforms.issues_braze b
left join jira.releases c on b.version_id=c.versionid
  • Related