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 8523867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:31:56+00:00 2026-06-11T07:31:56+00:00

I’m having a problem in grouping and sorting data in our daily time record

  • 0

I’m having a problem in grouping and sorting data in our daily time record to
automatically produce a report. The table structure of the DTR as follows:

LogDate     LogTime     EmployeeName            LogType
2012-09-14  10:48:04    SALITA, LYNYRD ANTONIO  LOGOUT
2012-09-14  09:39:29    SALITA, LYNYRD ANTONIO  LOGOUT
2012-09-14  09:39:19    SALITA, LYNYRD ANTONIO  LOGIN
2012-09-14  09:35:25    SALITA, LYNYRD ANTONIO  LOGOUT
2012-09-14  09:35:13    SALITA, LYNYRD ANTONIO  LOGIN
2012-09-14  08:10:00    SALITA, LYNYRD ANTONIO  LOGIN
2012-09-13  17:00:00    SALITA, LYNYRD ANTONIO  LOGOUT
2012-09-13  08:05:00    SALITA, LYNYRD ANTONIO  LOGIN
2012-09-12  17:05:00    SALITA, LYNYRD ANTONIO  LOGOUT
2012-09-12  08:05:00    SALITA, LYNYRD ANTONIO  LOGIN
2012-07-10  17:00:00    MAG-ISA, MAYBELLE       LOGOUT
2012-07-10  17:00:00    BELO, RIO               LOGOUT
2012-07-10  17:00:00    CANSINO, PAUL           LOGOUT
2012-07-10  17:00:00    SALITA, LYNYRD ANTONIO  LOGOUT
2012-07-10  17:00:00    AURENO, LEAH            LOGOUT
2012-07-10  17:00:00    GARCIA, ALVIN           LOGOUT
2012-07-10  17:00:00    TARINE, KAREN           LOGOUT
2012-07-10  17:00:00    REYES, ANDREA           LOGOUT
2012-07-10  17:00:00    NAVARRO, KRISTINA       LOGOUT
2012-07-10  10:30:00    MAG-ISA, MAYBELLE       LOGIN
2012-07-10  08:00:00    SALITA, LYNYRD ANTONIO  LOGIN
2012-07-10  08:00:00    CANSINO, PAUL           LOGIN
2012-07-10  08:00:00    BELO, RIO               LOGIN
2012-07-10  07:40:00    AURENO, LEAH            LOGIN
2012-07-10  07:30:00    GARCIA, ALVIN           LOGIN
2012-07-10  07:25:00    TARINE, KAREN           LOGIN
2012-07-10  07:10:00    NAVARRO, KRISTINA       LOGIN
2012-07-10  07:10:00    REYES, ANDREA           LOGIN

with this sql:

SELECT 
    DATE_FORMAT(LogDate, '%d/%c/%Y') AS LogDate, 
    EmployeeName,
    (GROUP_Concat(CASE LogType WHEN 'LOGIN' THEN LogTime END)) AS LOGIN,
    (GROUP_Concat(CASE LogType WHEN 'LOGOUT' THEN LogTime END)) AS LOGOUT
FROM myTable
GROUP BY LogDate, EmployeeName
ORDER BY LogDate desc;

I am able to produce this result

LogDate     EmployeeName            Login                       Logout
2012-09-14  SALITA, LYNYRD ANTONIO  08:10:00,09:35:13,09:39:19  09:35:25,09:39:29,10:48:04
2012-09-13  SALITA, LYNYRD ANTONIO  08:05:00                    17:00:00
2012-09-12  SALITA, LYNYRD ANTONIO  08:05:00                    17:05:00
2012-07-10  REYES, ANDREA           07:10:00                    17:00:00
2012-07-10  NAVARRO, KRISTINA       07:10:00                    17:00:00
2012-07-10  TARINE, KAREN           07:25:00                    17:00:00
2012-07-10  GARCIA, ALVIN           07:30:00                    17:00:00
2012-07-10  AURENO, LEAH            07:40:00                    17:00:00
2012-07-10  CANSINO, PAUL           08:00:00                    17:00:00
2012-07-10  SALITA, LYNYRD ANTONIO  08:00:00                    17:00:00
2012-07-10  BELO, RIO               08:00:00                    17:00:00
2012-07-10  MAG-ISA, MAYBELLE       10:30:00                    17:00:00

Based from one of the answers this is the code:

SELECT DATE_FORMAT(t1.LogDate, '%d/%c/%Y') AS LogDate, t1.EmployeeName
     , t1.LogTime AS Login
     , ( SELECT MIN(t2.LogTime) FROM myTable t2
          WHERE t2.LogType = 'LOGOUT'
            AND t2.LogDate = t1.LogDate
            AND t2.EmployeeName = t1.EmployeeName
            AND t2.LogTime > t1.LogTime ) AS Logout
  FROM myTable t1
 WHERE t1.LogType = 'LOGIN'

and it produced this result:

LogDate     EmployeeName            Login       Logout
2012-09-14  SALITA, LYNYRD ANTONIO  08:10:00    09:35:25
2012-09-14  SALITA, LYNYRD ANTONIO  09:35:13    09:35:25
2012-09-14  SALITA, LYNYRD ANTONIO  09:39:19    09:39:29
2012-09-13  SALITA, LYNYRD ANTONIO  08:05:00    17:00:00
2012-09-12  SALITA, LYNYRD ANTONIO  08:05:00    17:05:00
2012-07-10  REYES, ANDREA           07:10:00    17:00:00
2012-07-10  NAVARRO, KRISTINA       07:10:00    17:00:00
2012-07-10  TARINE, KAREN           07:25:00    17:00:00
2012-07-10  GARCIA, ALVIN           07:30:00    17:00:00
2012-07-10  AURENO, LEAH            07:40:00    17:00:00
2012-07-10  CANSINO, PAUL           08:00:00    17:00:00
2012-07-10  SALITA, LYNYRD ANTONIO  08:00:00    17:00:00
2012-07-10  BELO, RIO               08:00:00    17:00:00
2012-07-10  MAG-ISA, MAYBELLE       10:30:00    17:00:00

Is there any a way to make the result sort like this?

LogDate     EmployeeName            Login       Logout
2012-09-14  SALITA, LYNYRD ANTONIO  08:10:00    NULL
2012-09-14  SALITA, LYNYRD ANTONIO  09:35:13    09:35:25
2012-09-14  SALITA, LYNYRD ANTONIO  09:39:19    09:39:29
2012-09-14  SALITA, LYNYRD ANTONIO  NULL        10:48:04
2012-09-13  SALITA, LYNYRD ANTONIO  08:05:00    17:00:00
2012-09-12  SALITA, LYNYRD ANTONIO  08:05:00    17:05:00
2012-07-10  REYES, ANDREA           07:10:00    17:00:00
2012-07-10  NAVARRO, KRISTINA       07:10:00    17:00:00
2012-07-10  TARINE, KAREN           07:25:00    17:00:00
2012-07-10  GARCIA, ALVIN           07:30:00    17:00:00
2012-07-10  AURENO, LEAH            07:40:00    17:00:00
2012-07-10  CANSINO, PAUL           08:00:00    17:00:00
2012-07-10  SALITA, LYNYRD ANTONIO  08:00:00    17:00:00
2012-07-10  BELO, RIO               08:00:00    17:00:00
2012-07-10  MAG-ISA, MAYBELLE       10:30:00    17:00:00
  • 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-11T07:31:57+00:00Added an answer on June 11, 2026 at 7:31 am

    Something like this:

    SELECT DATE_FORMAT(t1.LogDate, '%d/%c/%Y') AS LogDate, t1.EmployeeName
         , t1.LogTime AS Login
         , ( SELECT MIN(t2.LogTime) FROM myTable t2
              WHERE t2.LogType = 'LOGOUT'
                AND t2.LogDate = t1.LogDate
                AND t2.EmployeeName = t1.EmployeeName
                AND t2.LogTime > t1.LogTime ) AS Logout
      FROM myTable t1
     WHERE t1.LogType = 'LOGIN'
    

    No GROUP BY is really necessary since you’re not actually grouping anything.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I am currently running into a problem where an element is coming back from
I want to construct a data frame in an Rcpp function, but when I
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.