Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL to combine child records by joining parent record
    primarykey
    data
    text
    <p>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.</p> <p>I have two tables JOBS and PHASES.</p> <pre><code>JOBS Id Job_Type (ex. 0 = import) Title PHASES Id Jobs_Id Phase_Type Title Start_Time End_Time Duration </code></pre> <p>Each job/job_type can have any number of phases - each phase has a start, end, and duration time</p> <p>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)</p> <pre><code>SELECT jobs_id, start_time, end_time, duration FROM phases JOIN jobs ON phase.jobs_id = jobs.id WHERE jobs.job_type=0 </code></pre> <p>return jobs_id return the earlist start time as start return the lastest endtime as end return the total duration of them all TotalDuration</p> <p>Example, if the following data was in the JOBS table (Id, Job_Type, Title)</p> <pre><code>1, 0, Import </code></pre> <p>and the following data was in PHASES table (id, job_id, phase_type, title, start, end, duration)</p> <pre><code>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 </code></pre> <p>Above shows the imformation (phases) of two jobs (job_type = 0)</p> <p>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)</p> <pre><code> 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 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload