Re: SQL - histogram - Mailing list pgsql-sql

From Richard Huxton
Subject Re: SQL - histogram
Date
Msg-id 00cf01c109e8$be6a8880$1001a8c0@archonet.com
Whole thread Raw
In response to SQL - histogram  (msalt@uol.com.br (Txugo))
List pgsql-sql
From: "Txugo" <msalt@uol.com.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
-----150160
(2 rows)

richardh=> select cm,count(id) from people, heights where height>=cm group
by cm;cm  | count
-----+-------150 |     4160 |     2
(2 rows)

HTH

- Richard Huxton



pgsql-sql by date:

Previous
From: "Richard Huxton"
Date:
Subject: Re: Problems with PG_DUMP and restore
Next
From: "Richard Huxton"
Date:
Subject: Re: "Display of specified number of records."