Skip site navigation (1) Skip section navigation (2)

Query query

From: Andrew Bell <acbell(at)iastate(dot)edu>
To: pgsql-novice(at)postgresql(dot)org
Subject: Query query
Date: 2001-11-27 19:00:55
Message-ID: 5.1.0.14.2.20011127125342.04b61900@acbell.mail.iastate.edu (view raw or flat)
Thread:
Lists: pgsql-novice
Hi,

You have all been so helpful, I'm going to bother you with another.  Say 
that you have a table with two categories.  I want to do a *single* query 
that shows the number of things in each of the primary category that match 
a constraint and
the number of things that don't match that constraint.

Given the following table and the constraint cat2 = 1

cat1  |  cat2

A        1
B        1
A        2
B        2
B        3
B        3

I want to generate output that looks like:

cat1  | count  | count
A         1        1
B         1        3

Where the first 'count' represents the number of things that match the 
constraint, and the second 'count' represents the number of things that 
doesn't match the constraint.

Can this be done?  If so how?

Thanks,


-- Andrew Bell
acbell(at)iastate(dot)edu
        


Responses

pgsql-novice by date

Next:From: Vincent.GaboriauDate: 2001-11-28 08:37:18
Subject: Re: [HACKERS] upper and lower doesn't work with german
Previous:From: Andrew BellDate: 2001-11-27 18:53:13
Subject: Re: Error

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group