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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:47:04+00:00 2026-05-30T01:47:04+00:00

I have three tables in my database. First table is Employee : Second table

  • 0

I have three tables in my database.

First table is Employee:

enter image description here

Second table is EmployeeTimeIn : (HoursConsumed have time in seconds!)

enter image description here

Third table is EmployeeTimeOut:

enter image description here

I wrote the following SQL query which lists all the employees grouped by their IDs and working time of each time in session:

select 
    v.EID, e.EmployeeName, v.Time_In, v.Time_Out,
    convert(varchar(5), SUM(v.HoursConsumed) / 3600)  + ':' + 
    convert(varchar(5), SUM(v.HoursConsumed) % 3600 / 60) + ':' + 
    convert(varchar(5), (SUM(v.HoursConsumed) % 60)) as workingtime,
    v.Date_Ref
from
    (select 
         e1.EID, e1.Time_In, e2.Time_Out, e1.HoursConsumed,    
         CONVERT(VARCHAR(10), e1.Date_Ref, 111) as Date_Ref
     from EmployeeTimeIn as e1, EmployeeTimeOut as e2
     where e1.Refid = e2.Refid) as v, Employee as e
     where v.EID = e.EmployeeID
     group by 
          v.EID, e.EmployeeName, v.Time_In, v.Time_Out, v.HoursConsumed, v.Date_Ref;

It produces the following output:

enter image description here

I need to modify this query so that for each employee it shows the grand total working time in workingtime column. In this scenario It will display workingtime of 0:41:53 for EID 4 and 0:0:39 for EID 200.

Please advise.

(NOTE: final output should have three rows for this example data because i need to show Time In and Time Out fields in final table too!)

  • 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-30T01:47:05+00:00Added an answer on May 30, 2026 at 1:47 am

    I assume that you always can convert WorkingTimeInSeconds to hours:

    ;WITH Totals(WorkingTimeInSeconds, EmployeeId, EmployeeName, DateRef) AS
    (
       SELECT 
          e.EmployeeId,
          e.EmployeeName,
          eti.Date_Refб
          SUM(HoursConsumed) WorkingTimeInSeconds,
        FROM Employee e
        JOIN EmployeeTimeIn eti
          ON e.EmployeeId = eti.EId
        GROUP BY 
          e.EmployeeId,
          e.EmployeeName,
          eti.Date_Ref
    )
    
    SELECT
      Totals.EmployeeId,
      Totals.EmployeeName,
      eti.Time_In,
      eto.Time_Out,
      eti.Ref_Date,
      eti.WorkingTimeInSeconds
    FROM Totals
    JOIN EmployeeTimeIn eti
      ON Totals.DateRef = eti.Date_Ref AND eti.EID=Totals.EmployeeId
    JOIN EmployeeTimeOut eto
      ON Totals.DateRef = eto.Date_Ref AND eto.EID=Totals.EmployeeId AND eti.RefId = eto.RefId
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's some background info. I have three MySQL tables (all InnoDB). The first table
I have a databse with three tables. The first table is something like: _id
I have three database tables: users emails invitations Emails are linked to users by
I have a database with three tables: user_table country_table city_table I want to write
I have a MySql database with three tables I need to combine in a
I have three tables in the many-to-many format. I.e, table A, B, and AB
I have three tables in a MySQL database used in a music library application:
I have a table in my database with 2 rows of employee data. ...........
I have many tables in my database which are interrelated. I have a table
I have two models in LINQ to SQL. First is Employee and the second

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.