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

Re: Cross-classified table

From: Bruno LEVEQUE <bruno(dot)leveque(at)net6d(dot)com>
To: Alexander Pucher <pucher(at)atlas(dot)gis(dot)univie(dot)ac(dot)at>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Cross-classified table
Date: 2003-10-20 19:53:09
Message-ID: 3F943D25.80206@net6d.com (view raw or flat)
Thread:
Lists: pgsql-novice
The query :

select origin, sex, count(sex) from table group by origin, sex;

gives the result :

 origin |  sex   | count
--------+--------+-------
 China  | male   |     2
 UK     | male   |     1
 USA    | female |     1
 USA    | male   |     2
(4 rows)


Is it enought ?

Bruno



Alexander Pucher wrote:

> Hi,
> I'm looking for the correct syntax of getting a cross-classified table 
> from my SELECT statement.
>
> Let's pretend I have this table:
>
>
> origin        sex
> ----------------
> USA        male    USA        female
> China      male
> China      male
> UK           male
> USA        male
>
>
> and I want as result something like:
>
>               male      female
>
> USA        2            1     China      2            0
> UK           1            0
>
>
> How can I get this?
>
> Best regards,
> alex
>
>  
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 7: don't forget to increase your free space map settings
>

-- 
Bruno LEVEQUE
System Engineer
SARL NET6D
bruno(dot)leveque(at)net6d(dot)com
http://www.net6d.com



In response to

pgsql-novice by date

Next:From: Muhyiddin A.M HayatDate: 2003-10-21 11:41:59
Subject: Re: Cross-classified table
Previous:From: Alexander PucherDate: 2003-10-20 16:01:20
Subject: Cross-classified table

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