Click here to Skip to main content
15,894,337 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have one UserLog table in sql which contains UserName and DateTimeData fields. One user can login and logout several times in a day. So I have to generate one view or query to show the X username and his/her firstlogindatetime and lastlogoutdatetime and total usage of the software for that particular day and particular user. Same thing i have to repeat for all the users and dates. Finally, I need to write the query for get the each UserName by Date and their FirstLogin and LastLogout as well as TotalTimeWorked. My Data type for UserName is nvarchar(50) and for DateTimeData is nvarchar(50). One username should appear only once for day. But it can show firstlogin and lastlogout in separate columns. Can u guys pls help me and guide me in this thing?
Thanks in advance:)

What I have tried:

I have to write the sql query to get desired output
Posted
Updated 20-Feb-17 12:02pm
v2
Comments
ZurdoDev 20-Feb-17 15:46pm    
Where are you stuck?
Graeme_Grant 20-Feb-17 15:47pm    
What have you tried so far?
j snooze 20-Feb-17 17:39pm    
Google Min, Max, and Sum aggregates for SQL Server, that should help give you an idea where to start. Feel free to post your attempts so we can point out what else you might need.

1 solution

I would do this a 'bit differently' than the guys in the comments

- I'd write 'n' queries, where a query might be to get the data for user x for day y
- I'd use PetaPoco to extract that data and return an object list
- I'd then use LINQ to aggregate (possibly group) the objects

The unfortunate thing is, you have to make a start and supply 'something' for whichever approach you decide to use ie 'pure sql' or basic sql & LINQ - people here wont write your code for you
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900