0

我正在尝试跟踪用户登录应用程序时的用户数据。我试图从我的查询(如下)中提取的是过去 30 天或更长时间未登录的所有用户。但是,它正在吸引最近登录的用户。帮助?

SELECT UserNM AS [UserID], MAX(EventDT) AS [Last Log-in Date]
FROM dbo.USREventLog
WHERE ABS(DATEDIFF([day], EventDT, GETDATE())) > 30

    AND (UserNM NOT LIKE 'user1') AND (UserNM NOT LIKE 'user2')
    AND (UserNM NOT LIKE 'user3') AND (UserNM NOT LIKE 'user4')

GROUP BY UserNM

顺便说一句,我使用他们最近的活动记录作为他们的最后一次登录日期,并且我有一小部分绝对不应该包含在结果中的用户。

4

2 回答 2

1

试试这个:

SELECT UserNM AS [UserID], MAX(EventDT) AS [Last Log-in Date]
FROM dbo.USREventLog
WHERE EventDT < GETDATE() - 30

    AND (UserNM NOT LIKE 'user1') AND (UserNM NOT LIKE 'user2')
    AND (UserNM NOT LIKE 'user3') AND (UserNM NOT LIKE 'user4')

GROUP BY UserNM, EventDT
于 2013-02-05T18:34:34.007 回答
0

我在其他地方找到了另一种解决方案。查询粘贴在下面。

SELECT UserID, [Last Login Date] from (
    SELECT UserNM AS [UserID], MAX(EventDT) AS [Last Login Date]
    FROM dbo.TSEventLog 
    WHERE (UserNM NOT LIKE 'user 1') AND (UserNM NOT LIKE 'user2')
    GROUP BY UserNM) x
WHERE ABS(DATEDIFF(day, [Last Login Date], GETDATE())) > 30
ORDER BY [UserID] ASC
于 2013-02-06T22:47:33.793 回答