Time Span?
I am trying to get the net days for a time span, starting from first step through to the last step. I have a few issues that I have to account for:
• The problem is overlap time. Some steps overlap; with their start days coming before the end of the previous step.
• There could be gaps from end of 1 step till start of the next.
I know I could min and max step days or count total days from table but that does not take the overlap into consideration. I have provided an example below.
CREATE TABLE claims_step_table (
table_id INTEGER PRIMARY KEY,
record_id NUMBER,
step_code VARCHAR2(20 Byte),
start_date DATE,
end_date DATE,
days NUMBER
truncate table claims_step_table;
INSERT INTO claims_step_table VALUES (1, 123456,'P96','01-JAN-09','10-JAN-09',10);
INSERT INTO claims_step_table VALUES (2, 123456,'L61','10-JAN-09','15-JAN-09',5);
INSERT INTO claims_step_table VALUES (3, 123456,'H45','12-JAN-09','20-JAN-09',8);
INSERT INTO claims_step_table VALUES (4, 123456,'O87','10-FEB-09','15-FEB-09',5);
COMMIT;
P96 |----------- 10 --------|
L61 |-----5-----|
H45 |--------8----------|
O87 |-----5-----|So the net should be 25 days because there is a 3 day overlap between step L61 and H45. Thanks for your help ahead of time.
Rich
GOOD CATCH, my fault record #4 should have been in FEB, cut and paste error.
Edited by: LostOne on Oct 15, 2009 8:19 AM
Using the tabibitosan method:
with cst as (select 1 table_id, 123456 record_id, 'P96' step_code, to_date('01/01/2009', 'dd/mm/yyyy') start_date, to_date('10/01/2009', 'dd/mm/yyyy') end_date, 9 days from dual union all
select 2 table_id, 123456 record_id, 'L61' step_code, to_date('10/01/2009', 'dd/mm/yyyy') start_date, to_date('15/01/2009', 'dd/mm/yyyy') end_date, 5 days from dual union all
select 3 table_id, 123456 record_id, 'H45' step_code, to_date('12/01/2009', 'dd/mm/yyyy') start_date, to_date('20/01/2009', 'dd/mm/yyyy') end_date, 8 days from dual union all
select 4 table_id, 123456 record_id, 'O87' step_code, to_date('22/01/2009', 'dd/mm/yyyy') start_date, to_date('27/01/2009', 'dd/mm/yyyy') end_date, 5 days from dual union all
select 5 table_id, 123457 record_id, 'P96' step_code, to_date('22/02/2009', 'dd/mm/yyyy') start_date, to_date('24/02/2009', 'dd/mm/yyyy') end_date, 2 days from dual union all
select 6 table_id, 123457 record_id, 'L61' step_code, to_date('01/01/2009', 'dd/mm/yyyy') start_date, to_date('11/01/2009', 'dd/mm/yyyy') end_date, 10 days from dual union all
select 7 table_id, 123455 record_id, 'L61' step_code, to_date('18/01/2009', 'dd/mm/yyyy') start_date, to_date('19/01/2009', 'dd/mm/yyyy') end_date, 5 days from dual union all
select 8 table_id, 123457 record_id, 'H45' step_code, to_date('02/01/2009', 'dd/mm/yyyy') start_date, to_date('05/01/2009', 'dd/mm/yyyy') end_date, 5 days from dual union all
select 9 table_id, 123455 record_id, 'H45' step_code, to_date('22/01/2009', 'dd/mm/yyyy') start_date, to_date('27/01/2009', 'dd/mm/yyyy') end_date, 5 days from dual),
-- end of mimicking your data
tabibitosan as (select table_id,
record_id,
step_code,
start_date,
end_date,
dense_rank() over (order by start_date, end_date, table_id) -
row_number() over (partition by record_id order by start_date, end_date) difference
from cst),
results as (select record_id,
max(end_date) - min(start_date) no_of_days
from tabibitosan
group by record_id,
difference)
select record_id,
sum(no_of_days) total_days
from results
group by record_id
order by record_id;
RECORD_ID TOTAL_DAYS
123455 6
123456 24
123457 12NB. you had 10 days covering 1st Jan - 10th Jan, but 5 days covering 10th Jan - 15th Jan - this isn't consistent!
Regardless, you do not need to store the number of days difference in the table - it only encourages errors like that! Just calculate the difference on the fly.
Similar Messages
-
Query Question - Linking in Time Span Data to Point-in-Time References
I am trying to pull historical data from a time-span table of records, using another point-in-time reference. I have been unsuccessful.
I've thrown some sample tables and data together to illustrate what I am seeking:
Create Table EmployeeInfo (
id Number(10,0), -- Employee ID Number
Name VarChar2(32 Byte), -- Employee Name
CurrentShift VarChar2(2 Byte) -- Current Employee Shift
Create Table ShiftChanges (
id Number(10,0), -- Employee ID that this shift change record is for
ChangeDate Date, -- Date that this Change Took Place
OldShift VarChar2(2 Byte),
NewShift VarChar2(2 Byte)
Create Table TimeCard(
id Number(10,0), -- Employee ID Number for this Timecard
WorkDay Date, -- What Day is this Timecard for?
Hours Float(63) -- Number of Hours worked.
COMMIT;
INSERT INTO EmployeeInfo VALUES (100,'John Doe','Days')
INSERT INTO EmployeeInfo VALUES (101,'Jane Doe','Days');
INSERT INTO TimeCard VALUES (100, to_date('01012010','ddmmyyyy'), 10.5);
INSERT INTO TimeCard VALUES (101, to_date('01012010','ddmmyyyy'), 10);
INSERT INTO TimeCard VALUES (100, to_date('02012010','ddmmyyyy'), 9);
INSERT INTO TimeCard VALUES (101, to_date('02012010','ddmmyyyy'), 10.5);
INSERT INTO TimeCard VALUES (100, to_date('03012010','ddmmyyyy'), 8);
INSERT INTO TimeCard VALUES (101, to_date('03012010','ddmmyyyy'), 7);
INSERT INTO ShiftChanges VALUES (100, to_date('02012010','ddmmyyyy'), 'Nights', 'Days');
COMMIT;I could do a query such as:
SELECT TC.id,
EM.Name,
TC.Workday,
EM.CurrentShift AS Shift
FROM TimeCard TC,
EmployeeInfo EM
WHERE (TC.ID=EM.ID(+));But it will not give me the historical shift, only the current. Since John Doe changed shifts on Jan 2 from Nights to Days, the above query would not reflect it.
I have attempted to join the historical table using a less-than operator. This doesn't work since more than one row can be returned.
SELECT TC.id,
EM.Name,
TC.Workday,
SC.NewShift AS Shift
FROM TimeCard TC,
EmployeeInfo EM,
ShiftChanges SC
WHERE (TC.ID=EM.ID(+)) AND
(TC.ID=SC.ID(+) AND TC.WORKDAY<=SC.WORKDAY(+));The problem stems from the fact that you need to examine multiple records in one table in order to obtain the correct historical data for the other.
The following SQL script {color:green}does work{color} - if the values are defined ahead of time.
DEFINE EMPID=101;
DEFINE CHGDATE=to_date('01/01/2010','dd/mm/yyyy');
SELECT SQ.Shift
FROM (SELECT ShiftChanges.NewShift AS Shift,
RANK() OVER (ORDER BY ShiftChanges.ChangeDate DESC) R
FROM ShiftChanges
WHERE ShiftChanges.id = &EMPID AND
ShiftChanges.ChangeDate <= &CHGDATE
) SQ
WHERE R = 1However, I have been unsuccessful in adapting it to the example tables I provided. If I insert the query as an inline subquery* in the select statement, it won't work, since the criteria is nested two levels down, and I can only get parent values within the first level.
I haven't thought of a way I can do this using a nested subquery - I keep running into that problem - how do you link in Time-Span data with a point-in-time reference.
Any ideas / enlightening thoughts?
Thank You
{size:8}_SELECT * FROM V$VERSION information:_
Oracle9i Enterprise Edition Release 9.2.0.8.0 - Production
PL/SQL Release 9.2.0.8.0 - Production
"CORE 9.2.0.8.0 Production"
TNS for 32-bit Windows: Version 9.2.0.8.0 - Production
NLSRTL Version 9.2.0.8.0 - Production
{size}
user10879184 re-wrote the original post on 29-Mar-2010 1:21 PM to reflect suggestions made by poster.I changed the tables to hold VARCHAR2(6) shift information and your query to reference the ChangeDate column.
I also assume you meant to link a TimeCard entry with the most previous ShiftChange entry rather than one that occurs after the time worked (TC.WORKDAY>=SC.CHANGEDATE(+) rather than TC.WORKDAY<=SC.CHANGEDATE(+)):
Another issue you don't take into account the case where there has been no shift change. In that event you need the current shift from the EmployeeInfo table which is taken care of with the NVL function.
You correctly note that multiple shift change records will result in duplicate TimeCard records though your test data fails to check for that condition. I added this row:
SQL> INSERT INTO ShiftChanges VALUES (100, to_date('03012010','ddmmyyyy'), 'Days', 'Nights'); Now it is apparent
SQL> SELECT TC.id,
2 EM.Name,
3 TC.Workday,
4 NVL(SC.NewShift,EM.CurrentShift) AS Shift
5 FROM TimeCard TC,
6 EmployeeInfo EM,
7 ShiftChanges SC
8 WHERE TC.ID=EM.ID(+) AND
9 TC.ID=SC.ID(+) AND TC.WORKDAY>=SC.CHANGEDATE(+);
ID NAME WORKDAY SHIFT
100 John Doe 01-JAN-10 Days
100 John Doe 02-JAN-10 Days
100 John Doe 03-JAN-10 Days
100 John Doe 03-JAN-10 Nights
101 Jane Doe 01-JAN-10 Days
101 Jane Doe 02-JAN-10 Days
101 Jane Doe 03-JAN-10 Days
7 rows selected.The reason for the duplicate Jan3 time is the two shift change records. We are matching both ShiftChange records that occured before the 3rd.
We also see that your test data has John starting out on Days and then shifting from Nights to Days on the 2nd for no real change. Fixing that:
SQL> DELETE from ShiftChanges where ID = 100;
2 rows deleted.
SQL> INSERT INTO ShiftChanges VALUES (100, to_date('02012010','ddmmyyyy'), 'Days', 'Nights');
1 row created.
SQL> INSERT INTO ShiftChanges VALUES (100, to_date('03012010','ddmmyyyy'), 'Nights', 'Days');
1 row created.Then:
SQL> SELECT TC.id,
2 EM.Name,
3 TC.Workday,
4 NVL(SC.NewShift,EM.CurrentShift) AS Shift
5 FROM TimeCard TC,
6 EmployeeInfo EM,
7 (SELECT ID, Workday, ChangeDate, NewShift
8 FROM
9 (SELECT TC2.ID, TC2.Workday, SC2.ChangeDate, SC2.Newshift,
10 MAX (SC2.ChangeDate) KEEP (DENSE_RANK LAST ORDER BY SC2.ChangeDate)
11 OVER (PARTITION BY SC2.ID, TC2.Workday) AS Max_ChangeDate
12 FROM ShiftChanges SC2,
13 TimeCard TC2
14 WHERE TC2.Workday >= SC2.ChangeDate
15 AND TC2.ID = SC2.ID
16 )
17 WHERE ChangeDate = Max_ChangeDate
18 ) SC
19 WHERE TC.ID=EM.ID(+) AND
20 TC.ID=SC.ID(+) AND
21 TC.Workday=SC.ChangeDate(+) AND
22 TC.Workday = SC.Workday(+);
ID NAME WORKDAY SHIFT
100 John Doe 01-JAN-10 Days
100 John Doe 02-JAN-10 Nights
100 John Doe 03-JAN-10 Days
101 Jane Doe 01-JAN-10 Days
101 Jane Doe 02-JAN-10 Days
101 Jane Doe 03-JAN-10 Days
6 rows selected.The inline view finds the greatest ChangeDate less than the TimeCard Workday for each Workday. -
Is it possible to set a default for "Time Span"?
AME seems to default to the Time Span to "Work Area" when rendering AE compositions. Is there any method, either in the app or by preference file hackery, to change this default to "Entire Composition?"
Coming from rendering in AE, this is a major problem for my workflow. You can't save this setting with a preset, like you can in AE, so I have to manually set this on every single comp I render. When I inevitably forget (about half the time or more), I end up with partial renders or having to cancel renders and start them over. Not fun.
I have submitted this as a feature request.I miss appointments b/c of this too.
And no, Apple does not read these forums UNLESS you comment on how pathetic and Mickey Mouse certain elements of their software is - like no 'default' setting for alarms in iCal, and not being able to resize windows from all edges (vs. the little annoying corner) etc etc.
I hope they fix it with the new software package in Leopard. I'm somewhat afraid it's going to be 'Leper' at first though. We'll see... -
How do you apply customized time spans to multiple files?
I have multiple different movie files I am using to create TIFFs. I have a customized render setting that I apply to all of the different files in the render queue. Once I apply this Render Setting to all of the files I am having to click on that setting and customize it for time span for a specific end. This customization option is not available when creating the original customized Render Setting. Is there a way to apply this specific time span to all of the different files other than having to click on each individual file separately?
No. Off hand I'm not even aware of a script for this, but something like this one might be possible to modify to suit your needs.
Mylenium -
How to reduce iCal event time span?
How do I set default time span of an event to 1 hour in iCal? I'm using Version 5.0.2 (1571) and the current default is set to something like 6 or 8 hours and it's driving me nuts! A related aggravation is that an event can unintentionally end up spanning 2 days! It used to work just fine in previous versions -- why did they "fix" this and how do I make the current version be truly useful like the old version?
Hi,
I guess you are adding events in Month view. From iCal's help file about entering events in Month view.
Add a new event in Month view by double-clicking within the day you want the event to appear. Enter a name and time duration for the event in the event’s title field, and then press Return.
iCal moves the event to the correct time and sets it to the correct duration. For example, you can double-click within a day in Month view, enter “Movie 7-9pm,” and then press Return.
If you don’t enter a time duration, iCal sets the event’s duration to 1 hour.
If you don’t enter any time information, iCal makes the event an all-day event.
Add a start time in the event title to make a timed 1 hour event. The time part of the title is stripped out.
Best wishes
John M -
Not getting Yahoo emails on Q5 except for a specific time span
My Q5 started to have this issue started about 4, 5 days ago. I dont get any Yahoo emails except for an approx 5 hr time span at specific times of the day. All other times I do not get any emails at all, not even when pressing the "refresh" icon.
I have deleted / rebooted/re-added the yahoo account multiple times without any improvement. I have also tested for improvement by taking away the "rim." in the settings (IMAP and SMPT), no help.
Well, right after re-adding the acct, the missing emails showed up, but that was it. It doesn't update my emails until that specific time of the day (for me that time span is from midnight to ~5am). I'm able to send out email fine.
Anyone has any suggestions?
Thank you very much in advance.Re: Yahoo.ca email account information disappears or is not recognized
11-25-2013 08:53 PM
The password disappeared again, so I changed the password as you suggested.
I discovered that Yahoo had changed the password requirements, and that was likely causing the problem.
(I wish the error message had been more specific so I would have known that was the issue earlier).
I created a new password according to the new Yahoo password requirements, and I have not had any other problems with it so far.
Thanks.
It was not me it was user cb_ca and the above is what they posted. You can ask that user your question, just click the envelope icon on the middle of the page near the top and you can send them a message, just enter the users name mentioned above and type your message. -
Fourier Analysis : wavelength longer than time span ??
Hi all,
I am running the Simulate->Analysis->Fourier Analysis of multisim
But it always shows "wavelength longer than time span" after a few minutes of simulation, what does it mean ? Thanks.
P.S. My circuit has two signal source(100Hz and 1000Hz) and I want to see the frequency response of the whole system.
My setting in Fourier analysis :
Error message :Hi Derek,
As attahced, look forward to you help !!!
Nate
Attachments:
CW_Design_0116.ms11 593 KB -
Report of result recording for multiple batches in a given time span .
Dear team ,
I am looking for a standard SAP report that gives the details of result recording with all the characteristics for mulitple batches in a given span of time . The MICs will show the actual values recorded for each of the batches.
The colums may be like this
material/batche/lot/quanity/mic1 value/mic2 value/mic 3 value...........
A standard report is prefered and we would also like to have a trend analysis done for the batches .
Looking forward to hearing from you .
RamThanks for the answer Firefighter.... cheked the t code and seems to be useful . But I would like to have the report in the folowing format . Kindly guide.
SN MATERIAL BATCH INSPECTION LOT QUANTITY CHARACTERISTIC 1 CHARACTERISTIC 2 3 4
Ram -
Time span weekly and daily calendar view in APEX
I would like to display the start and end time of an event. At the moment I can only see how to select the start time.
On the daily and weekly calendar only the start time shows
Edited by: jandeny on 31-Jan-2010 10:48Hello Jan
When you say you want to display the start and end time of an event, how are you wnating to diasplay it? What is the context? In a report? Read only text?
Kind regards
Simon Gadd -
Fiscal Year Time Dimension - Month Time Span
I have a need to create a fiscal year time dimension and I created using Time Wizard in OWB. When I was developing BI Reports, I found some inconsistencies in Time dimension as it was showing figures in all the months of my first quarter of new financial year that Apr 2009 – Mar 2010. On close inspection of Time Dimension table I found that fiscal_month_time_span value varies from 35 to 28 to 29 for different months. i.e. it’s not matching with corresponding Calendar month. This means I am unable to plot data correctly using fiscal year dimension.
Maybe this is how it works in Oracle, but this does not solve my problem. Could anyone give me some solution for this ? My Fiscal year is from ‘1- Apr – 09’ to ’31-Mar-10’. In my reports I would like to see transactions for April month when I use month attribute of time dimension like it happens in Calendar time dimension.May be someone from
Forum: Business Intelligence Suite Enterprise Edition can answer this .
Please post it there. -
Is there a limit to the time span on an asynchronous timer in CVI 7.0?
We're using an asynchronous timer to trigger recording data. TDUMP is
defined as a double (on the UIR) with +/- infinity limits. timedump is
also a double. TDUMP is in minutes, so we multiply by 60 to get seconds.
The code looks like ...
if (LOGSTAT == 0)
uir_err = GetCtrlVal (page_0, LABT0_TDUMP, &timedump);
timedump = timedump * 60;
err = SetAsyncTimerAttribute (g_logTimerID, ASYNC_ATTR_INTERVAL, timedump);
err = SetAsyncTimerAttribute (g_logTimerID, ASYNC_ATTR_ENABLED, 1);
The code works fine for TDUMP values of 7 or less. Somewhere between 7 and
8 the timer starts firing much too quickly. At 10 minutes (600 seconds)
we're seeing triggers at around 171 seconds.
Any suggestions about what the problem is?Hi all.
Is it only the time before the _first_ callback that is wrong? If so, what is probably happening is this:
1. You disable the timer, which suspends the callbacks
2. You set the interval to a different value
3. You re-enable the timer
From the help for SuspendAsyncTimerCallbacks():
"Stops all timer callbacks until a call is made to
ResumeAsyncTimerCallbacks.
Note: This function does not alter the ongoing schedule of timer
intervals. It merely inhibits the calling of callback
functions."
The new interval will not be implemented until the next timer tick after Step 3 above.
To prevent this happening, you need to call DiscardAsyncTimer(), then when you want to resume, call NewAsyncTimer() with the new interval.
Check out this discussion for more information.
Colin. -
How to specify time Spans for Message Trace in wpf Application
I had been working on this report on Message trace in Office365. I would want to give filters for Startdate and enddate from my WPF(C#) application. How can i do that.
i tried the following. When i specify them directly in the URL. they work perfectly fine but when i try to give them from the code, thats where it says value cannot be null,Parameter name: Source. What could be the problem.
ub.Query="$filter=StartDate eq datetime'2015-01-01T00:00:00' and EndDate eq datetime'2015-01-07T23:59:59' &";
string fullRestURL = Uri.EscapeUriString(ub.Uri.ToString());
ub.Query = "$filter=StartDate%20eq%20datetime%272015-01-01T05:00:00%27%20and%20EndDate%20eq%20datetime%272015-01-11T06:00:00%27%20&";
string fullRestURL = Uri.EscapeUriString(ub.Uri.ToString());Hi HarshitaK,
This forum(WPF) is talk about how to use XAML technologies to productively create visually appealing and differentiating applications and to improve user experience.
I found your question is about MessageTrace report:
http://msdn.microsoft.com/EN-US/library/office/jj984335(v=office.15).aspx
The Exchange Server Development is a better place for Office365/Exchange development questions. I’ve moved it there for you.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
Having some connection problems, but can only see past one day in the Event Log. Get message "Limit of uservisible log" where in settings can I increase the report time to see past week or so, in Event Log ?
It sounds like you have a home hub 3 with the latest firmware?
You mean it looks like this - <<<<<<<<<<<<<<<<<<<< Limit of uservisible log >>>>>>>>>>>>>>>>>>>>
I get the same. The hub event log used to give 3 full pages of events, now the maximum I get is 2 full pages and 7 events logged on the 3rd page (uses around ¼ of the page).
You can't increase this, though if you have many events stored prior to the limit message, you could try switching the hub off to remove these older events or bite the bullet and factory reset the hub.
-+-No longer a forum member-+- -
Where do I set the "Time Span: Length of Comp" in an Adobe Media Encoder Preset?
Since Adobe is removing H.264 from After Effects, I'm trying to get the workflow set up with AME. However, when I send a comp to AME, it doesn't render the whole comp, just the work area.
How can I set it up to automatically render the entire comp, like I do with the Render Queue?Just open up the render settings and look at the bottom. Render settings is where you would expect to find the render settings. Double click any file in the cue to open.
-
Display contents of a loop with time gaps in between
Hi,
I have a peculiar problem.
Consider a "for" loop
for ( i in 1..10)
In the above loop i want to display each value of "i" after a certain time span ( say, 1 sec).
In java, i could have used a "delay" function,but i do not know as how to achieve the same in javafx.
Please help me.
Thanks in advance.Something like that probably:
def seq:Integer[] = [1..10];
var bound:Integer = 0;
def anim:PauseTransition = PauseTransition {
duration: 1s
repeatCount: sizeof seq
action: function():Void {
var m:String = "";
for (i in [0..bound]) {
m = "{m} {seq}";
msg = m.trim();
bound++;
anim.play();
Maybe you are looking for
-
Combining results with a Query of Queries - NOT QUITE THERE!!!
I have included a small sample of my database, specifically the four tables I am trying to work with in the hopes that someone can steer me down the right path. Here are the four tables and the bottom is a visual desciption of what I am trying to ach
-
Gathering statistics in 8.1.7.4
Hi I 10g there is a default job to collect statistics can somebody refer me to code that can do the same on 8.1.7.4 in 8.1.7.4 also is the "bytes" column in the dba_tables is updated automatically , when rows inserted and deleted. or we need to dbms_
-
Where to buy in India ink cartridge for deskjet 2050 bought from Dubai
I bought HP DESKJET 2050 MODEL NOJ510a product no CH350C FROM DUBAI AND WAS USING CARTRIDGE NO 122. NOW I am in India and that no cartridge is available. What shall I do. Computer shop salesman said it is not available and to get from Dubai. Oto. Thi
-
The video specs for the Windbox state, "CRT + DVI, CRT + HDMI." How does one accomplish the "CRT + DVI"? With a Startech DVI-I-to-VGA splitter, I only get cloned displays. Thanks.
-
IDVD 08 crashes right before burning
I installed this overtop of iDVD5, and ever since, I haven't been able to make a DVD. As it is encoding, the program abruptly turns off, no error messages, nothing. I've read some other threads about this, and I have plenty of hard drive space, I tri