Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Help with a subtraction statement

TRAGHMJan 3 2020 — edited Jan 6 2020

I am trying to write a statement that counts the number of people that passes a scanner in a day.  the day does not start a zero for value.   I look for the 1st date in the row and move from there. 

the issue is the number resets.  For example

Location     Scanner     Date                                                           Value

Forw          1                    Sep 10, 2019 10:10:01                              14,345

Forw          1                    Sep 10, 2019 10:10:02                              14,349

Forw          1                    Sep 10, 2019 13,34,02                              15,035

Forw           1                   Sep 10, 2019 14:35:03                              15,459

Forw           1                   Sep 10, 2019 14:48:01                                   239

Forw           1                   Sep 10, 2019 15:56:13                                   500

The way the data works is I look for the 1st time of the and subtract that value from the last time of the date prior to a decrease in value.

What I am looking for is

Location     Scanner     Date                                                  Value

Forw           1               Sep 10                                             1,114                       --this is the difference between the 1st value of the day and the last value before a decrease in value

Forw          1                Sep 10                                                 261                      --this is the difference between the 1st value after a decrease and the value before the next decrease in vale or the last value of the day whichever  happens 1st

I don't know what function to use to make this work....

Comments
Post Details
Added on Jan 3 2020
5 comments
398 views