Re: Oracle Analytical Functions
От | Adam Rich |
---|---|
Тема | Re: Oracle Analytical Functions |
Дата | |
Msg-id | 00ff01c8641b$e70777a0$b51666e0$@r@sbcglobal.net обсуждение исходный текст |
Ответ на | Re: Oracle Analytical Functions (Enrico Sirola <enrico.sirola@gmail.com>) |
Ответы |
Re: Oracle Analytical Functions
Re: Oracle Analytical Functions |
Список | pgsql-general |
> > I'm trying to replicate the use of Oracle's 'lag' and 'over > > partition by' analytical functions in my query. I have a table > > (all_client_times) such as: > > and I would like to create a new view that takes the first table and > > calculates the time difference in minutes between each row so that > > the result is something like: I thought of a another way of doing this. In my tests, it's a little faster, too. DROP SEQUENCE if exists seq1; DROP SEQUENCE if exists seq2; CREATE TEMPORARY SEQUENCE seq1 CACHE 1000; CREATE TEMPORARY SEQUENCE seq2 CACHE 1000; select a.client_id, b.datetime, a.datetime as previousTime, (b.datetime - a.datetime) as difftime from (select nextval('seq1') as s, client_id, datetime from all_client_times order by client_id, datetime OFFSET 0) as a inner join (select nextval('seq2') as s, client_id, datetime from all_client_times order by client_id, datetime OFFSET 0) as b on a.s=(b.s-1) where a.client_id=b.client_id
В списке pgsql-general по дате отправления: