Complex LEFT JOIN not working as expected
问题 DBMS is intersystems-cache! Here is my full query: SELECT m.Name AS MessageType, COUNT(l.name) AS MessageCount, CAST(AVG(ResponseTime) AS DECIMAL(5, 2)) AS AvgResponseTime FROM (SELECT DISTINCT(name) FROM ENSLIB_HL7.Message) m LEFT JOIN ( SELECT CAST(li.SessionId AS Bigint) AS session_id, li.name, MIN(li.TimeCreated) AS SessionStart, MAX(lo.TimeCreated) AS SessionEnd, CAST(DATEDIFF(s, MIN(li.TimeCreated), MAX(lo.TimeCreated)) AS DECIMAL(5, 2)) AS ResponseTime FROM (SELECT h1.SessionId, h1