Re: [GENERAL] How can I calculate differences between values

2009-11-10 Thread Andrei
Hi; also you can try this query which should work for any version SELECT a.userid, a.data, max(f.data), a.data - max(f.data) FROM (SELECT userid, data FROM foo EXCEPT SELECT userid, min(data) FROM foo GROUP BY userid) a LEFT JOIN foo f ON (f.userid = a.userid AND f.data < a.data) GROUP B

Re: [GENERAL] How can I calculate differences between values

2009-11-10 Thread A B
> With 8.4's analytic capabilities you can do this: > select * from ( >   select userid, data - lag(data) over (partition by userid order by data) > diff >     from foo) q >   where diff is not null; Thank you! That worked perfectly! -- Sent via pgsql-general mailing list (pgsql-general@postgres

Re: [GENERAL] How can I calculate differences between values

2009-11-10 Thread Vyacheslav Kalinin
With 8.4's analytic capabilities you can do this: select * from ( select userid, data - lag(data) over (partition by userid order by data) diff from foo) q where diff is not null; On Tue, Nov 10, 2009 at 5:40 PM, A B wrote: > Hello there! > > I have a tablefoo( userid integer, data

Re: [GENERAL] How can I calculate differences between values

2009-11-10 Thread Richard Broersma
On Tue, Nov 10, 2009 at 6:40 AM, A B wrote: > For example > if the table contains: > > 4, 100 > 5, 200 > 5, 210 > 5, 231 > > > I want the values > > 5,10 > 5,21 > I guess that will work, but I'm curious, are there other ways? I think this kind of operation is best suited for CTEs and Windowing.

[GENERAL] How can I calculate differences between values

2009-11-10 Thread A B
Hello there! I have a tablefoo( userid integer, data integer); with the constraint unique(userid,data) Now I wish to select one userid and calculate the differences between the data -values (when they are sorted) . For example if the table contains: 4, 100 5, 200 5, 210 5, 231 I want the