I'm trying to count the records of each period for specific employees. I already removed unnecessary records by using "row_number() over (partition by...", then in the select, above I counted and grouped them to show how many times they exist for a given period number. The output and my SQL looks like this:
SELECT TBL.Name, TBL.Period_ID, count(*) as PeriodCount from (
Select row_number() over (partition by TBL1.Period_Id, TBL1.Name, TBL1.Date order by
TBL1.Period_Id desc) as rn1, * from (
<selected columns>
...
<joins>
...
<where clause>
...
) as TBL1
)as TBL
where TBL.rn1 = 1
Group by TBL.Name, TBL.Period_ID
order by 1
Output:
But what I actually want is to show all the periods for all users even with 0 as counted values. The desired output should look like:
I've already tried using the solution with left join
How to include "zero" / "0" results in COUNT aggregate?
after ")TBL" section but results stay the same.
Can you help me with this, please? :)
Bart