Greg Stark <gsstark(at)mit(dot)edu> writes:
> What would be useful is something like
> SELECT item_id,
> first(price) as min_price, first(store_id) as min_store,
> avg(price) as avg_price,
> last(price) as max_price, last(store_id) as min_store,
> count(distinct store_id) as num_stores
> FROM (SELECT * FROM items_for_sale ORDER BY item_id, store_id)
> GROUP BY store_id
Write it yourself --- both first() and last() are trivial to code as
user-defined aggregates.
regards, tom lane