Search notes:

Oracle SQL MODEL: Using analytic clauses

create table tq84_model_analytic(
   id   integer primary key,
   txt  varchar2(10)
);
 
begin
   insert into tq84_model_analytic values (1, 'one'  );
   insert into tq84_model_analytic values (2, 'two'  );
   insert into tq84_model_analytic values (3, 'three');
   insert into tq84_model_analytic values (6, 'six'  );
   insert into tq84_model_analytic values (9, 'nine' );
   commit;
end;
/
 
select
   *
from
   tq84_model_analytic
model
   dimension by (
      id
   )
   measures (
      txt,
      cast(null as number(4)      )  pos,
      cast(null as varchar2(20)   )  prev_txt
   )
   rules (
     pos     [any] = row_number(   ) over (order by id),
     prev_txt[any] = lag       (txt) over (order by id)
   );
--
--         ID TXT               POS PREV_TXT           
-- ---------- ---------- ---------- --------------------
--          1 one                 1                    
--          2 two                 2 one                
--          3 three               3 two                
--          6 six                 4 three              
--          9 nine                5 six    

See also

An example that demonstrates the combination of analytic clauses with the model clause is incremental string concatenation.

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758207103, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/databases/Oracle/SQL/select/model/analytic(74): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78