So, Here are the tables-
create table person (
id number,
name varchar2(50)
);
create table injury_place (
id number,
place varchar2(50)
);
create table pe
If you use Oracle 11g or above you can use pivot function for your required output.
SELECT *
FROM (
SELECT id
,place
,round((
cnt / sum(cnt) OVER (
ORDER BY NULL
)
) * 100, 2) AS pct
FROM (
SELECT a.id
,a.place
,count(a.id) AS cnt
FROM injury_place a
JOIN person_injuryPlace_map b ON a.id = b.injury_id
GROUP BY a.id
,a.place
)
)
pivot(max(id) , max(pct) pct FOR place IN (
'kitchen' AS kitchen
,'Washroom' Washroom
,'Rooftop' Rooftop
,'Garden' Garden
))