Re: [SQL] obtaining difference between minimum value and next in size

2010-11-18 Thread Oliveiros d'Azevedo Cristina
John, Great to hear it helped you out Best, Oliver - Original Message - From: John Lister To: pgsql-sql@postgresql.org Sent: Wednesday, November 17, 2010 10:46 PM Subject: Re: [SQL] obtaining difference between minimum value and next in size Cheers oliverios and tom for

Re: [SQL] obtaining difference between minimum value and next in size

2010-11-17 Thread John Lister
groups. John - Original Message - From: Oliveiros d'Azevedo Cristina To: John Lister ; pgsql-sql@postgresql.org Sent: Wednesday, November 17, 2010 4:09 PM Subject: Re: [SQL] obtaining difference between minimum value and next in size Hi, John. I am not familiar wit

Re: [SQL] obtaining difference between minimum value and next in size

2010-11-17 Thread Oliveiros d'Azevedo Cristina
Hi, John. I am not familiar with the functions Tom's indicated and I'm sure they constitute a much more straightfoward to solve your problem. Meanwhile, if you'd like to solve it with just SQL give this a try and see if it gives you the result you want Best, Oliveiros SELECT product_id, MIN(p

Re: [SQL] obtaining difference between minimum value and next in size

2010-11-17 Thread Andreas Kretschmer
John Lister wrote: > Hi, I was wondering if it is possible to do this with a single query rather > than iterate over all of the rows in an application: > > I have a table which for brevity looks like: > create table offers { > integer id; > integer product_id; > double price; > } > > wh

Re: [SQL] obtaining difference between minimum value and next in size

2010-11-17 Thread Tom Lane
"John Lister" writes: > Is it possible to obtain the difference between just the minimum price and > the next one up per product, If you're using >= 8.4, try a window function. LEAD or LAG ought to do it. regards, tom lane -- Sent via pgsql-sql mailing list (pgsql-sql