Author |
Topic |
MichelleMabbs
Starting Member
24 Posts |
Posted - 2014-12-02 : 11:14:51
|
I would like to recreate the following tableI have tried a windowing function but with no luck as the current value will exceed the total value as time ticks on through out the dayif someone could find a resolution to return the flag column I would be gratefulAreA Time On Plan Report Retrieved Flag LatestReportUK 07:50:00 02/12/2014 15:00 Total 3UK 06:33:00 02/12/2014 15:00 Current 3UK 07:50:00 02/12/2014 16:00 Total 2UK 06:53:00 02/12/2014 16:00 Current 2UK 07:50:00 02/12/2014 17:00 Total 1UK 07:59:00 02/12/2014 17:00 Current 1Wales 06:00:00 02/12/2014 15:00 Total 3Wales 05:50:00 02/12/2014 15:00 Current 3Wales 06:00:00 02/12/2014 16:00 Total 2Wales 05:52:00 02/12/2014 16:00 Current 2Wales 06:00:00 02/12/2014 17:00 Total 1Wales 06:55:00 02/12/2014 17:00 Current 1Michelle |
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2014-12-02 : 11:30:31
|
Given this data, what would the results of a correct query look like? |
|
|
MichelleMabbs
Starting Member
24 Posts |
Posted - 2014-12-02 : 11:37:15
|
Hi sorry to mislead that table is how I would like it to look likeAreA Time On Plan Report Retrieved Flag LatestReportUK 07:50:00 02/12/2014 15:00 Total 3UK 06:33:00 02/12/2014 15:00 Current 3Michelle |
|
|
MichelleMabbs
Starting Member
24 Posts |
Posted - 2014-12-02 : 11:37:16
|
Hi sorry to mislead that table is how I would like it to look likeAreA Time On Plan Report Retrieved Flag LatestReportUK 07:50:00 02/12/2014 15:00 Total 3UK 06:33:00 02/12/2014 15:00 Current 3Michelle |
|
|
MichelleMabbs
Starting Member
24 Posts |
Posted - 2014-12-02 : 11:40:24
|
sorry its not clear, I require it to be like the one attached, I am struggling to format the tablearea 'time on plan' reportretrieved flag 'latest report'uk 07:50 01-12-2014 15:00 Total 3uk 06:50 01-12-2014 15:00 Current 3uk 07:50 01-12-2014 16:00 Total 2uk 06:59 01-12-2014 16:00 Current 2uk 07:50 01-12-2014 17:00 Total 1uk 07:59 01-12-2014 17:00 Current 1Michelle |
|
|
MichelleMabbs
Starting Member
24 Posts |
Posted - 2014-12-02 : 11:41:32
|
Basically a windowing rank function will not suffice as the current value will eventually exceed the total valueI am trying to flag the duplicated times on plan so I can have two tables one with the total values and one with the current values in hope it makes senseMichelle |
|
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2014-12-02 : 11:42:59
|
OK -- though I don't understand how you compute the value for flag. |
|
|
MichelleMabbs
Starting Member
24 Posts |
Posted - 2014-12-02 : 11:45:40
|
so if the time on plan has a re occurring value such as 17:59:00 then flag it as say the total, if it is a new time then flag as Current.Michelle |
|
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2014-12-02 : 13:00:30
|
OK - since I don't have your whole query (or sample data) I can only give you a hint.SELECT ... , case count(*) over(partition by AreA, Time, [On Plan], [Report Retrieved], LatestReport) when 1 then 'Current' else 'Total' end as FlagFROM yourtable |
|
|
MichelleMabbs
Starting Member
24 Posts |
Posted - 2014-12-03 : 07:01:35
|
Hi thank you this has solved the problemMichelle |
|
|
|