pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Huxton <dev@archonet.com>
To: Txugo <msalt@uol.com.br>
To: pgsql-sql@postgresql.org
Subject: Re: SQL - histogram
Date: Wed, 11 Jul 2001 10:06:15 +0100
Message-ID: <00cf01c109e8$be6a8880$1001a8c0@archonet.com> (raw)
References: <45809a56.0107090919.177def5b@posting.google.com>

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
-----
 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




view thread (3+ messages)

Message-ID: <00cf01c109e8$be6a8880$1001a8c0@archonet.com>
Permalink:  ../00cf01c109e8$be6a8880$1001a8c0@archonet.com/
Also on:    postgresql.org/message-id/00cf01c109e8$be6a8880$1001a8c0@archonet.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: dev@archonet.com, msalt@uol.com.br
  Subject: Re: SQL - histogram
  In-Reply-To: <00cf01c109e8$be6a8880$1001a8c0@archonet.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox