Quantcast
Channel: SCN: Message List - SAP HANA and In-Memory Computing
Viewing all articles
Browse latest Browse all 8968

Re: Creating a Circular Log/History Table

$
0
0

This will create a simple circular table:

 

Drop table T3;

CREATE TABLE T3 (KEY INT, ROW INT PRIMARY KEY, USER INT, VAL INT);

UPSERT T3 SELECT COALESCE(MAX(KEY), 0) + 1, (select MOD(COALESCE(MAX(KEY), 0), 5) + 1 from T3 where USER = 1), 1, 1 FROM T3 ;

UPSERT T3 SELECT COALESCE(MAX(KEY), 0) + 1, (select MOD(COALESCE(MAX(KEY), 0), 5) + 1 from T3 where USER = 1), 1, 1 FROM T3 ;

UPSERT T3 SELECT COALESCE(MAX(KEY), 0) + 1, (select MOD(COALESCE(MAX(KEY), 0), 5) + 1 from T3 where USER = 1), 1, 1 FROM T3 ;

UPSERT T3 SELECT COALESCE(MAX(KEY), 0) + 1, (select MOD(COALESCE(MAX(KEY), 0), 5) + 1 from T3 where USER = 1), 1, 1 FROM T3 ;

UPSERT T3 SELECT COALESCE(MAX(KEY), 0) + 1, (select MOD(COALESCE(MAX(KEY), 0), 5) + 1 from T3 where USER = 1), 1, 1 FROM T3 ;

UPSERT T3 SELECT COALESCE(MAX(KEY), 0) + 1, (select MOD(COALESCE(MAX(KEY), 0), 5) + 1 from T3 where USER = 1), 1, 1 FROM T3 ;

UPSERT T3 SELECT COALESCE(MAX(KEY), 0) + 1, (select MOD(COALESCE(MAX(KEY), 0), 5) + 1 from T3 where USER = 1), 1, 1 FROM T3 ;

 

select * from T3;

 

This will produce:

 

KeyROWUSERVAL
6111
7211
3311
4411
5511

 

I would prefer to have a Unique Key on Row, USER so that I can rotate over the unique key for multiple users. Any insights?


Viewing all articles
Browse latest Browse all 8968


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