, : ("role A" , "role B" , "role C" , "role D"
), .
:
SELECT cast(matrix_view.droit_name as text),
matrix_view.droit_id || ',' || sum(case when matrix_view.aid = 1 then matrix_view.aid end) || ',' || sum(case when matrix_view.aid = 1 then haspair end) as "role A" ,
matrix_view.droit_id || ',' || sum(case when matrix_view.aid = 2 then matrix_view.aid end) || ',' || sum(case when matrix_view.aid = 2 then haspair end) as "role B" ,
matrix_view.droit_id || ',' || sum(case when matrix_view.aid = 3 then matrix_view.aid end) || ',' || sum(case when matrix_view.aid = 3 then haspair end) as "role C" ,
matrix_view.droit_id || ',' || sum(case when matrix_view.aid = 4 then matrix_view.aid end) || ',' || sum(case when matrix_view.aid = 4 then haspair end) as "role D"
from (
SELECT allRD.aid as aid, allRD.droit_id,allRD.droit_name , max(case when RD.role_id is not null then 1 else 0 end) as HasPair
from (
select distinct a.role_id as aid, b.droit_id as droit_id , b.droit_name as droit_name
from role a cross join droit b
) as allRD
left outer join role_Droit RD
on allRD.aid = RD.role_id and allRD.droit_id = RD.droit_id
group by allRD.droit_id, allRD.aid ,allRD.droit_name
order by allRD.aid
) AS matrix_view
group by matrix_view.droit_id, matrix_view.droit_name
order by matrix_view.droit_id