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
Hi, thank you for taking the time one reading this, I would like to get the last 5 logins per user regardless of the computer (can be 5 times the same computer if the user only uses 1 computer or 5 different computers if the user normally logs in everywhere). Basically we want to identify users that are using computers that they shouldn't.
By the way, I tried your query but gives me the following error:
Error while saving report: "The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expression, unless TOP, OFFSET or FOR XML is also specified."