vertica sql delta -


i want calculate delta value between 2 records table got 2 column id , timestamp want calculate delta time between records

    id  |timestamp |delta ----------------------------------     1   |100       |0     2   |101       |1 (101-100)     3   |106       |5 (106-101)     4   |107       |1 (107-106) 

i work vertica data base , want create view/projection of table on db.

is possible create calculate without using udf function?

you can use lag() purpose:

select id, timestamp,        coalesce(timestamp - lag(timestamp) on (order id), 0) delta t; 

Comments

Popular posts from this blog

javascript - How do you prevent nested queries/catches in sequelize? -

java - Could not retrieve pre-bound Hibernate session - Could not obtain transaction-synchronized Session for current thread -

java - ConcurrentModificationException upon committing transaction with Hibernate -