Unable to figure out accurate query to get timestamps for my report…for each user

为君一笑 提交于 2021-01-29 05:43:55

问题


I am trying to write a report based on data of users logging into a session.

I need to be able to get a full session time from when the first person joins the meeting to when the last person leaves.

When someone joins a meeting it is logged as, "Initialize-Load Video chat Window" There are 2 ways to close the meeting but one way is being logged. - There is an "End Chat" button that the user can use and that is logged as, "Video Chat-End Chat" - If the user does not use that button and just exits out the program/browser, the database does not log that, and I would like to use the last logged element in the logType column.

Taking what was given to me by @AlanSchofield from the link below....how can i use the previous query if i want to get the session times per user? Below is what i tried doing but It did not work as every user got the same times.

Below is the query I used;

    declare @MeetingSessionID varchar(500)
set @MeetingSessionID = '16052994739072114123-10133-45143-1301114'

SELECT DISTINCT 
       vl.originalChatSessionID, 
       vl.applicationUserID,
       vl.pharmaID,
        ou.FirstName,
        ou.MiddleName,
        ou.LastName,
        ou.FullName,
       VideoDate = MIN(vl.ReceivedDateTime) OVER(PARTITION BY vl.originalChatSessionID), 
       StartTime = MIN(ISNULL(sc.StartChat, vl.ReceivedDateTime)) OVER(PARTITION BY vl.originalChatSessionID),
       EndTime = MAX(ISNULL(ec.EndChat, vl.ReceivedDateTime)) OVER(PARTITION BY vl.originalChatSessionID),
       SessionLength = DATEDIFF(
                minute,
                MIN(ISNULL(sc.StartChat, vl.ReceivedDateTime)) OVER(PARTITION BY vl.originalChatSessionID), 
                MAX(ISNULL(ec.EndChat, vl.ReceivedDateTime)) OVER(PARTITION BY vl.originalChatSessionID)
                )
    FROM iclickphrDxvideolog vl
        LEFT JOIN (
                    SELECT originalChatSessionID, StartChat = MIN(ReceivedDateTime) 
                        from iclickphrDxvideolog
                        WHERE logType = 'Initialize-Load Video chat Window'
                        GROUP BY originalChatSessionID
                    ) sc ON vl.originalChatSessionID = sc.originalChatSessionID
        LEFT JOIN (
                    SELECT originalChatSessionID, EndChat = MAX(ReceivedDateTime) 
                    from iclickphrDxvideolog
                        WHERE logType = 'Video Chat-End Chat'
                        GROUP BY originalChatSessionID
                    ) ec ON vl.originalChatSessionID = ec.originalChatSessionID
        inner join iclickphrDxOtherUser ou
        on (vl.applicationUserID = ou.userID or vl.pharmaID = ou.userID)

where vl.originalChatSessionID = @MeetingSessionID
order by FullName

Please refer to link below to similar question, just need something more added for it. Similar question, just without users

来源:https://stackoverflow.com/questions/64840961/unable-to-figure-out-accurate-query-to-get-timestamps-for-my-report-for-each

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!