I have result like this
SubjectId ReasonId TypeId
1 1 0
1 1 0
1 2 0
1 2 0
1 3 0
1 4 1
1 4 1
1 6 1
1 6 1
2 1 0
...
...
...
But, I have to create report like following:
SubjectId ReasonId(Type0) Count(Type0) ReasonId(Type1) Count(Type1)
1 1 2 4 2
1 2 2 6 2
1 3 1 5 0
2 1 1 4 0
2 2 0 5 0
2 3 0 6 0
Let me explain:
Instead of showing result in standard view, where each record is new row, I must break result into two groups:
First group was fixed three rows per SubjectId
with value of TypeId = 0
, and for each Reason (1, 2, 3) I must show count of rows for specific reason. ReasonId must be sorted in descending order by count of rows.
Second group is located right of first group, and story is same, instead of TypeId = 0
there is TypeId = 1
. Same descending order is needed.
So, every SubjectId has exactly three rows for every ReasonId (for Type 0 there are reasons 1, 2, 3 and for Type 1 there are reasons 4, 5, 6).
If some subject has no rows for any reasons, I must write 0.