I have several users that each have a department they belong to and a integer which denotes (in days) when they last logged in.
A user can have several departments.
I am trying to group the users by department, vertically distribute them across three bins depending on when they logged in, and then uniquely count them.
If a user belongs to several departments i only want to count them once, it dosen't matter under which department they are being counted.
In my current solution a user with several departments gets counted once for
each department, which, given my solution, makes sense, but is not what I want.
If i try a distinct count it returns the same as each row is unique.
I'm using the MsSql Fiddle example except that I have added a
DaysSinceLastLogin (int) column that denotes when the user last logged in.
Uncomment the first sql block to see the 6 users and which departments they belong to.