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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:02:40+00:00 2026-06-13T06:02:40+00:00

First let me apologize if this doesn’t make any sense. I took me some

  • 0

First let me apologize if this doesn’t make any sense. I took me some time to write it up and understand it myself. I apologize if there is anything that is confusing. I am new to this and did my best to explain. I also apologize for the qustion title, if it doesn’t represent. If someone knows of a better title, please edit or make any changes necessary.

I have two tables JOBS and PHASES.

JOBS
Id
Job_Type (ex. 0 = import)
Title

PHASES
Id
Jobs_Id
Phase_Type
Title
Start_Time
End_Time
Duration

Each job/job_type can have any number of phases – each phase has a start, end, and duration time

I want to select the fields jobs_id, start_time, end_time, and duration from the PHASES table
and add up all their Durations for each job_type (example: job_type = 0 which is an import job)

SELECT jobs_id, start_time, end_time, duration FROM phases 
JOIN jobs ON phase.jobs_id = jobs.id
WHERE jobs.job_type=0

return jobs_id
return the earlist start time as start
return the lastest endtime as end
return the total duration of them all TotalDuration

Example, if the following data was in the JOBS table (Id, Job_Type, Title)

1, 0, Import

and the following data was in PHASES table (id, job_id, phase_type, title, start, end, duration)

1, 1, 1, 0, Run Preprocessor, 10/18/2012 8:52 PM, 10/18/2012 9:00 PM, 00:08:00
2, 1, 2, 1, Massage Data, 10/18/2012 9:00 PM, 10/18/2012 9:05 PM, 00:05:00
3, 1, 3, 2, Run Postprocessor, 10/18/2012 9:05 PM, 10/18/2012 9:07 PM, 00:02:00

4, 2, 1, 0, Run Preprocessor, 10/18/2012 9:15 PM, 10/18/2012 9:20 PM, 00:05:00
5, 2, 2, 1, Massage Data, 10/18/2012 9:20 PM, 10/18/2012 9:25 PM, 00:05:00
6, 2, 3, 2, Run Postprocessor, 10/18/2012 9:30 PM, 10/18/2012 9:35 PM, 00:05:00

Above shows the imformation (phases) of two jobs (job_type = 0)

I need an SQL statement that can combine the phases and show the earlist start and latest end, and the total duration. I would expect this information returned (Job_id, Start, End, TotalDuration)

 1, 10/18/2012 8:52 PM, 10/18/2012 9:07 PM, 00:05:00
 2, 10/18/2012 9:15 PM, 10/18/2012 9:35 PM, 00:15: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-13T06:02:41+00:00Added an answer on June 13, 2026 at 6:02 am

    Assuming your total durations will not go beyond 1 day, this will work. If it goes beyond one day, an additional expression will be required to preceed the HH:MM:SS in the duration column.

    select job_id,
           min(start_time) start_time,
           max(end_time) end_time,
           CONVERT(CHAR(8), max(end_time)-min(start_time), 8) totalduration
      from phases
     group by job_id
    
    -- sample data --
    create table phases (job_id int, start_time datetime, end_time datetime);
    insert phases values (1, '20121019 12:45', '20121019 13:15');
    insert phases values (1, '20121019 13:15', '20121019 13:45');
    insert phases values (1, '20121019 14:00', '20121019 15:12');
    
    -- result --
    job_id  start_time               end_time                 totalduration
    1       2012-10-19 12:45:00.000  2012-10-19 15:12:00.000  02:27:00
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First, let me apologize if this is the world's stupidest question. But, I'm stumped
First let me apologize a bit for the length of this post, it's mostly
First off, let me apologize if this has been asked already, but I can’t
First off, let me apologize if I'm writing this in the wrong place. I
Let me first apologize if this question could sound perhaps sort of amateurish for
First of all, let me apologize if this question is too broad. I'm looking
Let me first apologize. I've been coding for a long time now, but I'm
I apologize that the title may not make sense, so let me describe my
Ok. First let me apologize profusely if this question has been covered. I did
First let me apologize for the scale of this problem but I'm really trying

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.