I have a table with Incidents that contains column for number injured in the incident and column for number killed in that incident. Incident table is linked with Participants table where you can find a column for age of the person and there is another table ParticipantTypes with column for type(man(id = 1), woman(id = 2) for example). So, I want to retrieve column number injured, column number killed where type is a man and next to them column number injured, column number killed where type is a woman, all group by age.
select
ip.age as age,
sum(i.number_injured) as injured,
sum(i.number_killed) as killed
from Incidents i
inner join Participants ip on i.id = ip.incident_id
inner join ParticipantTypes ipt on ip.type_id = ipt.id
where ipt.id = 1
group by ip.age
the following query works and retrieve results only for ParticipantTypes.type = 1 (man)
I want it something like
select
ip.age as age,
sum(i.number_injured) as injured where ipt.id = 1,
sum(i.number_killed) as killed where ipt.id = 1,
sum(i.number_injured) as injured where ipt.id = 2,
sum(i.number_killed) as killed where ipt.id = 2,
from Incidents i
inner join Participants ip on i.id = ip.incident_id
inner join ParticipantTypes ipt on ip.type_id = ipt.id
group by ip.age