I have a requirement to find the logged in time of a user on the given time range in SQL server. The table has login_time and logout_time per user.
Sample data.
id user_id login_time logout_time
1 101 2023-05-02 14:10:00 2023-05-04 09:30:00
So If I search the report for duration between 2023-05-01 and 2023-05-05, the desired output is
date user_id login_duration_seconds
2023-05-01 101 0
2023-05-02 101 35400
2023-05-03 101 86400
2023-05-04 101 34200
2023-05-05 101 0
Can someone please help me build a query for the same.
2条答案
按热度按时间2izufjch1#
Try the following:
Output:
hsvhsicv2#
Assume that you have
login_history
table.Here is a query
Here is a updated query