Re: optimizing query with multiple aggregates

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On Wed, Oct 21, 2009 at 6:51 PM, Doug Cole <dougcole@xxxxxxxxx> wrote:

repeated across many different x,y values and fields to build out several histograms of the data.  The main culprit appears to be the CASE statement, but I'm not sure what to use instead.  I'm sure other people have had similar queries and I was wondering what methods they used to build out data like this?

Use group by with an appropriate division/rounding to create the appropriate buckets, if they're all the same size.

select round(field/100) as bucket, count(*) as cnt from foo group by round(field/100);

--
- David T. Wilson
david.t.wilson@xxxxxxxxx

[Postgresql General]     [Postgresql PHP]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Yosemite]

  Powered by Linux