→ 🚀What's New? Join Us for the Fall Product Launch! Register Now !
‎01-30-2018 12:30 AM
‎01-31-2018 10:35 PM
‎01-31-2018 10:27 PM
‎01-30-2018 06:19 PM
WITH TopFive AS
(
SELECT l.UserName, l.LogOnTime, a.AssetId, a.AssetName, ROW_NUMBER() OVER (PARTITION BY l.UserName ORDER BY l.LogOnTime DESC) AS RowNum
FROM tblAssets AS a
INNER JOIN tblCPLogOnInfo AS l ON a.AssetId = l.AssetId
)
SELECT UserName, LogOnTime, AssetId, AssetName
FROM TopFive
WHERE RowNum <= 5
ORDER BY UserName ASC, LogOnTime DESC
‎01-31-2018 08:41 PM
AZHockeyNut wrote:
well, depends what you mean by last 5 logins per user.
you could mean last 5 assets they logged into regardless of when, or you could mean the last 5 logontimes regardless of asset.
To get the last 5 logon times per user you would run something like this....
WITH TopFive AS
(
SELECT l.UserName, l.LogOnTime, a.AssetId, a.AssetName, ROW_NUMBER() OVER (PARTITION BY l.UserName ORDER BY l.LogOnTime DESC) AS RowNum
FROM tblAssets AS a
INNER JOIN tblCPLogOnInfo AS l ON a.AssetId = l.AssetId
)
SELECT UserName, LogOnTime, AssetId, AssetName
FROM TopFive
WHERE RowNum <= 5
ORDER BY UserName ASC, LogOnTime DESC
Experience Lansweeper with your own data. Sign up now for a 14-day free trial.
Try Now