Tomasz, > What about this: > select > event, > sum(case when level=1 then 1 else 0 end) as ones, > sum(case when level=2 then 1 else 0 end) as twos, > sum(case when level=3 then 1 else 0 end) as threes > from baz > group by event;
That version is only more efficient for small data sets. I've generally found that case statements are slower than subselects for large data sets. YMMV. BTW, while it won't be faster, Joe Conway's crosstab function in /tablefunc does this kind of transformation. -- Josh Berkus Aglio Database Solutions San Francisco ---------------------------(end of broadcast)--------------------------- TIP 4: Don't 'kill -9' the postmaster