From: | "Richard Huxton" <dev(at)archonet(dot)com> |
---|---|
To: | "Txugo" <msalt(at)uol(dot)com(dot)br>, <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: SQL - histogram |
Date: | 2001-07-11 09:06:15 |
Message-ID: | 00cf01c109e8$be6a8880$1001a8c0@archonet.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
From: "Txugo" <msalt(at)uol(dot)com(dot)br>
> I have a table where one record represent a person, including his height.
> I'd like to know how many person have more than 150 cm, more than 160 cm
> and so on.
> How can I do that using SQL?
>
> Example:
> people > 150 - 1000
> > 160 - 850
> > 170 - 500
> > 180 - 200
> > 190 - 30
> thanks in advance
richardh=> select * from people;
id | height
----+--------
1 | 150
2 | 155
3 | 160
4 | 165
(4 rows)
richardh=> select * from heights;
cm
-----
150
160
(2 rows)
richardh=> select cm,count(id) from people, heights where height>=cm group
by cm;
cm | count
-----+-------
150 | 4
160 | 2
(2 rows)
HTH
- Richard Huxton
From | Date | Subject | |
---|---|---|---|
Next Message | Richard Huxton | 2001-07-11 09:10:51 | Re: "Display of specified number of records." |
Previous Message | Richard Huxton | 2001-07-11 08:57:45 | Re: Group by date_part |