Quantcast
Channel: SCN : Unanswered Discussions - SAP HANA and In-Memory Computing
Viewing all articles
Browse latest Browse all 4343

DELETE SQL based on temporary values

$
0
0

Hi,

 

I am currently trying to create a procedure which deletes certain entries from a table on a daily basis.

The table is used to log changed values from BW including the user, time and date when the changes have been performed.

As the table would get bigger and bigger, I would like to write a procedure which keeps only the last entries of for each user.

 

I already have a SELECT function which describes the data I want to delete.

 

Thus I was not able so far to create a delete function out of this as there are two criteria in my WHERE clause which are not available in my table as fields (TIME_RANKING and USER_RANKING). Therefore I cannot just say DELETE FROM "SAPRBE"."ZIRSORT01_LOG" WHERE "TIME_RANKING" > 3....

 

How can I use fields in the WHERE clause of a DELETE function which do not belong to the affected table?

 

SELECT

"MYUSER"

, "MYDATE"

, "MYTIME"

, "CALYEAR"

, "CM_CDT2"

, "ZUEBERNAH"

FROM (

SELECT RANK() OVER (PARTITIONBY"CM_CDT2", "CALYEAR"ORDERBY"MYDATE", "MYTIME"DESC) AS"TIME_RANKING"

, RANK() OVER (PARTITIONBY"MYUSER", "CM_CDT2", "CALYEAR"ORDERBY"MYDATE", "MYTIME"DESC) AS"USER_RANKING"

, "MYUSER"

, "MYDATE"

, "MYTIME"

, "CALYEAR"

, "CM_CDT2"

, SUM("/BIC/ZUEBERNAH") AS"ZUEBERNAH"

FROM"SAPRBE"."ZIRSORT01_LOG"

GROUPBY"MYUSER"

, "MYDATE"

, "MYTIME"

, "CALYEAR"

, "CM_CDT2"

ORDERBY"CM_CDT2"DESC, "MYDATE"DESC, "MYTIME"DESC)

WHERE ("TIME_RANKING"> 3 OR"USER_RANKING" != 1) OR TO_DATE ("MYDATE") < (ADD_DAYS (CURRENT_DATE, -1095));


Viewing all articles
Browse latest Browse all 4343

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>