CREATE VIEW orchestration_logs_by_session AS
SELECT
os.orchestration_session_id,
onature.nature AS orchestration_nature,
osl.category,
COUNT(*) AS log_count
FROM orchestration_session os
JOIN orchestration_nature onature ON os.orchestration_nature_id = onature.orchestration_nature_id
JOIN orchestration_session_exec ose ON os.orchestration_session_id = ose.session_id
JOIN orchestration_session_log osl ON ose.orchestration_session_exec_id = osl.parent_exec_id
GROUP BY os.orchestration_session_id, onature.nature, osl.category