Advertisement

04.19.2008 at 02:07AM PDT, ID: 23336299
[x]
Attachment Details

SQL - Calculating Differences in Time Between Values in different columns

Asked by tonMachine100 in SQL Query Syntax, Oracle 8.x

Tags: oracle sql

Hello
 
I hope someone can help me with this query. unfortunately this one's beyond my sql reporting skills!
 
Please see the attachment for an example of the table I want to report from. This table records the length of time a certain event has been open - in this case, social work care plans.
 
The person_id and person_name record who the plan is recorded against, the plan_id is the unique identier for the plan, the plan start and end dates record how long each plan has been open for. The Plan length is a calculated field I've added (plan_end_Date - plan_start_date).
 
What I need is a report that will calculate how long each episode of plans has lasted, adding up the length of contiguous plans by client. For John Smith for example, I want to add the durations of plans 1, 2 and 3 but not plan 4 as there is a break in time of more than one day between the care_plan_end date of plan 3 and the start date of 4. In the example of roger Black Id want the lengths of plans 7 and 8 totaled but I would not want to total the lengths of either plan 6 or 9.
 
The attachment also has the kind of output that Id want from this report.
 
For your information, a person can only have one plan open at any point in time so the plan dates for a person would not overlap.
 
Hope you can help, thanks, tonmachine
Start Free Trial
Attachments:
 
sample table and expected report output
 
[+][-]04.19.2008 at 09:50AM PDT, ID: 21393130

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.19.2008 at 11:10AM PDT, ID: 21393384

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.19.2008 at 12:46PM PDT, ID: 21393643

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: SQL Query Syntax, Oracle 8.x
Tags: oracle sql
Sign Up Now!
Solution Provided By: Sqaimes
Participating Experts: 1
Solution Grade: B
 
 
[+][-]04.20.2008 at 05:48AM PDT, ID: 21395880

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628