| 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 |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| 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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Muhyiddin A.M Hayat | 2003-10-21 11:41:59 | Re: Cross-classified table |
| Previous Message | Alexander Pucher | 2003-10-20 16:01:20 | Cross-classified table |