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!

Setting flag

Ann 81Jun 22 2016 — edited Jun 22 2016

I Have a query which will calculate the number of orders on 5 days range.and planning to run daily.

SELECT         REQUESTED_DATE,  COUNT(Orders) REQUESTED_ORDERS

FROM            SVCO

WHERE  (TRUNC(UCBSVCO_REQUESTED_DATE) BETWEEN  TRUNC(SYSDATE)AND TRUNC(SYSDATE+5))

GROUP BY REQUESTED_DATE

ORDER BY 1

I need to set a Flag to Y or N based on the following requirement  ;

if requested orders >=350 and <=399 or  >=400 set flag to Y; if already the flag is set to Y by previous run  then flag should be N

Below is the sample scenarios. This query will be run everyday

    First day run

REQUESTED_DATEREQUESTED_ORDERS flag
6/23/2016189
6/24/201699
6/25/2016142
6/26/2016350y
6/27/2016348

Second day Run

   

REQUESTED_DATEREQUESTED_ORDERS flag
6/24/2016120
6/25/2016270
6/26/2016367N
6/27/2016359y
6/28/2016

100

Flag for 6/26/2016 is N because it already been set to Y for last run it will be N till the requested orders are crossing 400;then the flag would be Y.

6/27/2016 flag in Y ; because it was not in the previous run and it crossed 350

Third DayRun

   

REQUESTED_DATEREQUESTED_ORDERSflag
6/25/2016360y
6/26/2016380n
6/27/2016359n
6/28/2016310
6/29/2016360y

   

6/25/2016 flag is Y  because it never crossed 350 in previous run and never set a flag ;

6/26/2016 flag is still N becasue it never crossed 400 Yet

same with 6/27/2016

Forth day Run

   

REQUESTED_DATEREQUESTED_ORDERS
6/26/2016402Y
6/27/2016390n
6/28/2016350y
6/29/2016400y
6/30/2016279

   

6/26/2016 is set to Y becasue it crossed 400.

6/27/2016 is still N becasue it didt cross 400

And so on .

Can anyone tell me how to implement this. I can use procedure or temp tables etc..

Thanks,

Ann

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 20 2016
Added on Jun 22 2016
2 comments
866 views