The given below is the query:
SELECT
states.name,
equipment.type,
sum(equipment_events.total),
(SUM(equipment_locations.amount) - SUM(equipment_events.total))
FROM
States,
Locations,
Equipment_locations,
equipment,
equipment_events,
events
WHERE
equipment.id = equipment_events.equipment_id
and states.id = locations.state_id
and locations.id = events.location_id
and equipment.id = equipment_events.equipment_id
GROUP BY
states.name;