From: | ed(dot)temp(dot)01(at)gmail(dot)com |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | selects on differing subsets of a query |
Date: | 2006-05-03 08:47:49 |
Message-ID: | 306f0afd0605030147i598ba049q9ef55a3f3b08847c@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
First post, be gentle as I have terminology problems and so the
subject might be wrongly worded.
Say I have a table with fields
...
gender
diet_pref
...
What I am trying to construct is a *single* query showing the total
number of males in the table
and also the total number of male vegetarians in the table, i.e. the
2nd value is computed on a subset of the records needed for the first
value.
As 2 queries this would be:
select count(*) from mytab where gender='m'
select count(*) from mytab where gender='m' and diet_pref='veg'
The table is big and I'd like to do the select where gender='m' only
once. (In the actual situation the select is on a date range)
If there is a TFM, please point me at it with an indication of exactly
what it is I am trying to achieve. If I'm trying to do something
stupid, gentle advice would be appreciated.
From | Date | Subject | |
---|---|---|---|
Next Message | Markus Schaber | 2006-05-03 10:40:01 | Re: selects on differing subsets of a query |
Previous Message | Markus Schaber | 2006-05-03 08:07:35 | Re: Compute hash of a table? |