Multiple counts on criteria - Approach to a problem

From: Neil Saunders <n(dot)j(dot)saunders(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Multiple counts on criteria - Approach to a problem
Date: 2009-09-17 16:22:35
Message-ID: ddcd549e0909170922l169fbe34waad6fb2ca6ded296@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi all,

I maintain an online property rental application. The main focus of the UI
is the search engine, which I'd now like to improve by allowing filtering of
the search results shown on some criteria, but provide a count of the number
of properties that meet that criteria.

For example, we're looking all properties, no criteria. I'd like to show
something like:

Bedrooms:
1 Bedroom (122)
2 Bedrooms (143)
3 Bedrooms (88)

Facilities
BBQ (232)
Pool (122)

...and so on. My question is simple - What's the best way to implement this
- Do I literally have to execute a count for the WHERE criteria with the
filter criteria tagged on, or is there some clever trick that I'm not aware
of? I'd rather not count in the application as I'd like to plan for the day
we have up to 100k properties (

Any suggestions gratefully received!

Ta,

Neil.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2009-09-17 16:25:07 Re: COPY binary
Previous Message Paul M Foster 2009-09-17 16:10:46 Re: What kind of JOIN, if any?