Given the following data, how would I get the desired result below?
Timestamp | Session ID | Event | Name
------------------------------------------
08:15 | 89 | Login | Scott
08:16 | 89 | Edit | Scott
08:16 | 92 | Login | John
08:17 | 92 | Refresh | John
08:23 | 89 | Logout | Scott
08:28 | 92 | Logout | John
08:30 | 96 | Login | Scott
08:37 | 96 | Logout | Scott
Desired Result (essentially a list of session durations):
Name | Login | Logout
------------------------
Scott | 8:15 | 8:23
John | 8:16 | 8:28
Scott | 8:30 | 8:37
edit: extended sample data and results to avoid some confusion.
The query I'm actually needing to develop is much more complex . I just thought this would give me a good jumpstart on one of the logic hurdles. Since I know everyone will want to know what I've tried, here is my current, embarrassing, iteration from the actual structure...
SELECT
SessionId,
SAMLData_Organization,
(Select TimeCreated FROM ens.messageheader h1,HS_Message.XMLMessage m1 WHERE h1.SessionId = h3.SessionId and m1.name = 'XDSB_QueryRequest') as RequestRecieved,
(Select TimeCreated FROM ens.messageheader h1,HS_Message.XMLMessage m1 WHERE h1.SessionId = h3.SessionId and m1.name = 'XDSB_QueryResponse') as ResponseSent
FROM
ens.messageheader h3,HS_Message.XMLMessage m3
WHERE SessionId IN (SELECT Distinct SessionId FROM ens.messageheader WHERE TimeCreated >= '2016-08-22 08' AND TimeCreated < '2016-08-22 17')
Things I'm trying to tackle:
- Join
ENS.MessageHeader
andHS_Message.XMLMessage
- Get the
TimeCreated
value for messages of typeXDSb_QueryRequest
- Get the
TimeCreated
value for the correspondingXDSb_QueryResponse
using theSessionId
as a common value. - Return results as
Organization | RequestReceived | ResponseSent