Given the following very simple table:
Create Table tblUserLogins (
LoginNumber int PRIMARY KEY IDENTITY(1,1),
Username varchar(100),
LoginTime datetime
)
Basically when a user logs into the site, a record is created in this table, indicating the user logged in. (For security reasons the developers in my team do not have access to the tables holding the login information, so this was a work-around).
What I need, is some help writing a query which will actually return me the username of the user who logged on the most during a given period (supplied as input values to the procedure).
I can select the data between any 2 given dates using the following:
SELECT * FROM tblUserLogins
WHERE LoginTime BETWEEN @DateFrom AND @DateTo
However I am not sure how I can aggregate the user data, without first dumping the contents of the above query to a temporary table.
Any help would be gratefully received.
1 Answer