COUNT func

From: Oleg Lebedev <olebedev(at)waterford(dot)org>
To: Postgres SQL Mailing List <pgsql-sql(at)postgresql(dot)org>
Subject: COUNT func
Date: 2001-10-18 19:37:17
Message-ID: 3BCF2F6D.D404B26@waterford.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi,
I am trying to count the number or rows in a table with similar field
values. I want to do it in one table scan.
In other words, say I want to count the number of rows in Person table,
having age equal to 40, and the number of rows with status as 'married'.
I want Person table to be scanned only once during this query.
So, basically I want to do the following:
SELECT COUNT(age=40), COUNT(status='married')
FROM Person;

I tried to use aggregate functions with group by and having clauses, but
I still can't figure it out (probably because of the lack of
experience).
Please help.
Thanks,

Oleg

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Thomas Swan 2001-10-18 19:45:10 Granting database level permissions...
Previous Message Stephan Szabo 2001-10-18 19:25:14 Re: Doing a regexp-based search/replace?