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

  • Home
  • SEARCH
  • 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 6204289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:03:54+00:00 2026-05-24T05:03:54+00:00

I have 4 columns in my database UserName, Date, Time, LoginType UserName is a

  • 0

I have 4 columns in my database

UserName, Date, Time, LoginType

UserName is a varchar field
Date is a date field
Time is a time field (in 24 hour format)
LoginType is a varchar field

LoginType can contain one of the two strings “LOGIN”, “SHUTDOWN”

I want to get the average time someone will LOGIN or SHUTDOWN
I also want to know the delta of the lateless, earliness.

So for this example, lets assume that students must attent class by 8:30 and must LOGOFF by 10:30

So lets also assume the sample data is as follows

George.Lucas 8:45 2011-07-22 LOGIN
Eric.TheRed 9:00 2011-07-22 LOGIN
Dr.Who 9:01 2011-07-22 LOGIN
Dr.Who 11:01 2011-07-22 SHUTDOWN
George.Lucas 11:45 2011-07-22 SHUTDOWN
Eric.TheRed 12:00 2011-07-22 SHUTDOWN
  1. We can see that George was 15 min late and he shutdown 1hr 15min late
  2. Eric was 30 min late to login
  3. Eric was 2hr 30 min late to SHUTDOWN
  4. Dr.Who was 31 min late LOGIN
  5. Dr.Who was 31 min late SHUTDOWN

Thanks

  • 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-05-24T05:03:55+00:00Added an answer on May 24, 2026 at 5:03 am

    This will give you the average time a given user took between login and shutdown, even when there are multiple sessions for the same day, and assuming the user needs to shutdown before logging in again:

    SELECT login.UserName, 
      AVG(shutdown.Date - login.Date)
    FROM table login,
      table shutdown
    WHERE login.UserName = shutdown.UserName
          AND login.LoginType = 'LOGIN'
          AND shutdown.LoginType = 'SHUTDOWN'
          AND shutdown.Date = (SELECT MIN(t.Date)
                               FROM table t
                               WHERE t.UserName = login.UserName
                                     AND t.LoginType = 'SHUTDOWN'
                                     AND t.Date > login.Date)
    GROUP BY login.UserName;
    

    To find out the difference between the expected and effective login/shutdown time, you just need to subtract 8:30 and 10:30 from login.Time and shutdown.Time, respectively.

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

Sidebar

Related Questions

In my database, I have a few columns in one of my tables that
I have one database table which contains 8 columns. One of the columns is
I have one database which contains username, password and IsActive (data type is bit)
I have ten fields in my table in database..And two columns out of them
I have a database with columns (username, points). I am making a call to
Hi there in my database I have 3 columns, is_contract, is_permenant and is_temporary. Within
I've just come across a database where all the character based columns have their
I'm new to database indexing, if I have 2 columns in a table that
I have a table in my Postgres database with columns named type, desc, and
I have a java class containing all the columns of a database table as

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.