Dynamically displaying current value in following rows [message #500877] |
Thu, 24 March 2011 04:35 |
ankurjain
Messages: 11 Registered: July 2007 Location: Vadodara, Gujarat, India
|
Junior Member |
|
|
Hello Guys,
I have a problem where I have to display the value of current cell in next following cells.
The table structure is as follows :
ttdate - date
individualplanid - varchar(10); - train number
sch_deptime - number(8); - scheduled departure time in milli seconds
sch_arrtime - number(8); - scheduled arrival time in milli seconds
stn - varchar(10); - station short name
dep_delay - number(8); - dep delay in milli seconds
arr_delay - number(8); - arr delay in milli seconds
The delay is filled continuously by application software continuously.
I want to make a query where I want a calculated field which does the prediction of train arrival on coming stations. This shall be done as the delay + sch_deptime for all the next stations.
Following is a dataset :
individualplanid sch_deptime sch_arrtime stn arr_delay dep_delay
BO646 NULL 57900000 BVI NULL 80000
BO646 NULL 58140000 KILE NULL 40000
BO646 NULL 58320000 MDD NULL 20000
BO646 NULL 58530000 GMN NULL NULL
BO646 NULL 59160000 ADH NULL NULL
BO646 NULL 59550000 STC NULL NULL
BO646 NULL 59940000 BA NULL NULL
BO646 NULL 60540000 DDR NULL NULL
BO646 NULL 61200000 BCL NULL NULL
BO646 61800000 NULL CCG 12000 NULL
What I want to do is
individualplanid sch_deptime sch_arrtime stn arr_delay dep_delay EAT
BO646 NULL 57900000 BVI NULL 80000 57980000
BO646 NULL 58140000 KILE NULL 40000 58180000
BO646 NULL 58320000 MDD NULL 20000 58340000
BO646 NULL 58530000 GMN NULL NULL 58550000
BO646 NULL 59160000 ADH NULL NULL 59180000
BO646 NULL 59550000 STC NULL NULL 59570000
BO646 NULL 59940000 BA NULL NULL 59960000
BO646 NULL 60540000 DDR NULL NULL 60560000
BO646 NULL 61200000 BCL NULL NULL 61220000
BO646 61800000 NULL CCG 12000 NULL 61812000
The last column (EAT) is calculated one. It shall be like as the dep_delay is updated the EAT for the following records shall be sch_deptime + dep_delay. I tried my hand at windows and partitioning but not of much help.
I did was something like this. The calculated field is cum_depdelay which is only the delay ( not sch_deptime + dep_delay ).
select ttdate,individualplanid td,station,sch_deptime,sch_arrtime,act_depdelay,
sum(act_depdelay) over ( partition by individualplanid order by sch_deptime rows between current row and unbounded following ) c_depdelay
from logtime where ttdate='14-Mar-2011' and individualplanid='BO646'
order by sch_deptime,sch_arrtime;
TD STATION SCH_DEPTIME SCH_ARRTIME ACT_DEPDELAY C_DEPDELAY
BO646 BVI 57900000 NULL 80000 140000
BO646 KILE 58140000 NULL 40000 60000
BO646 MDD 58320000 NULL 20000 20000
BO646 GMN 58530000 NULL NULL NULL
BO646 ADH 59160000 NULL NULL NULL
BO646 STC 59550000 NULL NULL NULL
BO646 BA 59940000 NULL NULL NULL
BO646 DDR 60540000 NULL NULL NULL
BO646 BCL 61200000 NULL NULL NULL
BO646 CCG NULL 61800000 NULL NULL
Please guide me on how shall i proceed ?
-Ankur Jain
|
|
|
|
Re: Dynamically displaying current value in following rows [message #501015 is a reply to message #500884] |
Fri, 25 March 2011 02:05 |
ankurjain
Messages: 11 Registered: July 2007 Location: Vadodara, Gujarat, India
|
Junior Member |
|
|
Hello littlefoot,
Sorry my first post was a little messy. I will explain again in a little detail. This database keeps the information of a train's id,scheduled departure time ( for intermediate stations ) ,scheduled arrival time ( for last station ), stopping stations and delay. The delay field is updated as the train makes its journey by application software. Now I want to make a report where I will use this info and display a new value named EAT where I want to display the sch_deptime + arr_delay for next all stations. Its like estimated time of arrival depending on the delay for next all stations. This field is not in database it needs to be calculated. The query you gave is helpful. I will try to do some changes and try displaying it in report.
Thanks for prompt reply
-Ankur
[Updated on: Fri, 25 March 2011 05:24] Report message to a moderator
|
|
|