I have a table which tracks of activity when users from one specific app login and logout. But I have seen some cases where let's say a user logins at 11:40 on March 24th and then logins again at 11:55 on the same day without logging out. The application doesn't allow that but I am trying to create a report for users who have logged in twice without logging out. The case I described would have been ok, if the user had logged out before 11:55 am before logging back in. Can someone help with the logic? All I need is a list of users who have logged in twice without logging out.
action --This is where login and logout is captured.
"He who learns for the sake of haughtiness, dies ignorant. He who learns only to talk, rather than to act, dies a hyprocite. He who learns for the mere sake of debating, dies irreligious. He who learns only to accumulate wealth, dies an atheist. And he who learns for the sake of action, dies a mystic."[/i]
For a specific day, then:
,CAST(Date AS date) AS Date
Group By Name, Login_Email_Address, CAST(Date AS date) AS Date
Having Sum(Case When action = 'Login' Then 1 Else 0 End) >
Sum(Case When action = 'Logout' Then 1 Else 0 End)
SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.
This is another approach that will also work across days.
WITH ua AS
[action] --This is where login and logout is captured.
,LAG([action]) OVER(PARTITION BY Login_Email_Address ORDER BY [Date]) AS Prev_Action
WHERE [action] = Prev_Action
J. Drew Allen
Business Intelligence Analyst
Viewing 3 posts - 1 through 2 (of 2 total)