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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:48:50+00:00 2026-06-12T08:48:50+00:00

I have a large MySQL table which looks like this: job_number time_on time_off 111

  • 0

I have a large MySQL table which looks like this:

job_number        time_on        time_off
111               18:50:10       18:51:18
222               18:13:09       19:33:42
111               07:12:04       08:30:20
333               10:34:03       12:53:10
444               14:54:25       12:11:04
444               10:31:48       16:34:53
111               17:21:41       20:21:41
(type: Varchar)   (type: time)   (type: time)

I want to find the difference between the time_on and time_off fields for each job_number and echo them in the $total_time column.
If there are multiple rows with the same job_number (111, 444), i want to be able to find the difference between the time_on and the time_off for that row but also add these values together.
I would like to make sure there is only one row of each unique job number with the combined times like so:

Job    Total Time // ($total_time = $time_off - $time_on)
111    04:19:34 // ((18:51:18 - 18:50:10) + (08:30:20 - 07:12:04) +  (20:21:41 - 17:21:41))
222    01:20:33 // (19:33:42 - 18:13:09)
333    02:19:07 // (12:53:10 - 10:34:03)
444    08:46:26 // ((16:34:53 - 10:31:48) + (14:54:25 - 12:11:04))

the results will be formatted in a simple table like so:

<table>  
    <tr>  
        <th>Job</th>  
        <th>Total Time</th>  
    </tr>  
    <tr>  
        <td>111</th>  
        <td>04:19:34</th>
    </tr>
    <tr>  
        <td>222</th>  
        <td>01:20:33</th>
    </tr>
    ...
</table>

How would i go about doing this?
I would prefer to use PHP to achieve this. Any help would be greatly appreciated. Thankyou

  • 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-12T08:48:51+00:00Added an answer on June 12, 2026 at 8:48 am

    You could do it in SQL:

    SELECT   job_number,
             SEC_TO_TIME(SUM(TIME_TO_SEC(time_off) - TIME_TO_SEC(time_on)))
    FROM     my_table
    GROUP BY job_number
    

    See it on sqlfiddle.

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

Sidebar

Related Questions

i have a large mysql database table in which one column contains values ranging
I have a very large table in MySQL. I'm using a CHAR(32) field which
I have a large mysql table (about 5M rows) on which i frequently insert
I have a MySQL table with a large amount of records (~20k), which is
I have a MySQL database with a fairly large table where the products are.
Let's say I have a very large MySQL table with a timestamp field. So
We have a large MyISAM table that is used to archive old data. This
I currently have a large table in MySQL with several fields. I am currently
I have a large MySQL database, lets call it live_db , which I want
I have a fairly large mysql database and I would like to count all

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.