Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8121135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:23:07+00:00 2026-06-06T05:23:07+00:00

I’ve got a table with two columns Time and Login, showing when a user

  • 0

I’ve got a table with two columns Time and Login, showing when a user has sent calls during a day.

On a per user basis, I need to find the greatest, smallest and average session length where the session length is calculated as the time in minutes between the first call and the last call on any given day.

Table:

Time                Login
2012-05-29 20:01:26 A
2012-05-29 20:01:40 A
2012-05-29 20:02:27 A
2012-05-29 20:58:46 A
2012-05-29 20:59:50 A
2012-05-29 21:00:12 A
2012-05-29 21:00:36 A
2012-05-30 21:28:28 A
2012-05-30 21:29:08 A
2012-05-30 21:29:13 A
2012-05-30 21:29:25 A
2012-04-06 10:25:24 A
2012-04-06 10:25:53 A
2012-04-06 10:26:35 A
2012-04-27 12:05:45 A
2012-04-27 12:06:06 A

Desired output would look something like this:

MaxSession Login
59         A

As mentioned above the same output is required for MinSession and AverageSession.

I am completely stuck for hours and have really no clue how to get this done.

What I’ve achieved is to get the unique active days per Login.
I just cannot figure out how to achieve the next steps, though, which would be:

  • get the first entry per Login per day
  • get the last entry per Login per day
  • calculate the difference in minutes between last entry
    and first entry per day per Login as SessionLength
  • select the Max, Min, and Average SessionLenght per Logins

I would be very grateful for any type of help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T05:23:10+00:00Added an answer on June 6, 2026 at 5:23 am

    Try this

    Grouped by day

    Select Login,Date(Time) As LoginDay,Max(Time) As LastLogin,Min(Time) As FirstLogin,Count(*) As Logins,
    
    From LoginsTable
    Group By Login,Date(Time)
    Order By LoginDay,Login
    

    Please enclose columns in ‘ ‘ for the columns like ‘time’

    Max,Min and average sessions

        Select Login,Max(SessionMinutes) As MaxSessoin,Min(SessionMinutes) As MinSession,
        Avg(SessionMinutes) From
        (
            Select Login,
            LoginDay,LastLogin,FirstLogin,TotalLogins,Hour(DateDiff(LasTLogin-FirsTLogin))*60 + Minute(DateDiff(LasTLogin-FirsTLogin)) As SessionMinutes
            From
            (
                Select Login,Date(Time) As LoginDay,Max(Time) As LastLogin,Min(Time) As FirstLogin,Count(*) As Logins,
                From LoginsTable
                Group By Login,Date(Time)
            ) As Temp
        ) As Temp1
    

    Presently ignoring the seconds while calculating the minutes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help joining two table. I've got: my_type_table , which has columns:
I've got a table which has the usual ParentID, ChildID as it's first two
I got a table with a few columns. The table has a primary key
Say I've got a table with two columns (date and price). If I select
There are two tables table1 and table2 table1 has got two columns name and
I've got an anonymous table in which the are two columns: UserId and PhoneNumber.
I've got a table with two columns(among others): id and created_in_variant and a stored
I've got a simple table Logins with two columns: username (nvarchar) logged (datetime) It's
I've got two tables. Invoice with columns CustomerID, InvoiceDate, Value, InvoiceTypeID (CustomerID and InvoiceDate
I've got a table recording views of programs. Each program can have two different

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.