CREATE VIEW orchestration_session_duration AS
SELECT
os.orchestration_session_id,
onature.nature AS orchestration_nature,
os.orch_started_at,
os.orch_finished_at,
(JULIANDAY(os.orch_finished_at) - JULIANDAY(os.orch_started_at)) * 24 * 60 * 60 AS duration_seconds
FROM orchestration_session os
JOIN orchestration_nature onature ON os.orchestration_nature_id = onature.orchestration_nature_id
WHERE os.orch_finished_at IS NOT NULL