Received: from anchor-post-33.mail.demon.net (anchor-post-33.mail.demon.net [194.217.242.91]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f6B9XIa69335 for ; Wed, 11 Jul 2001 05:33:18 -0400 (EDT) (envelope-from dev@archonet.com) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-33.mail.demon.net with esmtp (Exim 2.12 #1) id 15KGMs-000MIV-0X; Wed, 11 Jul 2001 10:33:15 +0100 Received: from client (client.archonet.com [192.168.1.16]) by mainbox.archonet.com (Postfix) with SMTP id 044FA11EE2; Wed, 11 Jul 2001 10:06:18 +0100 (BST) Message-ID: <00cf01c109e8$be6a8880$1001a8c0@archonet.com> From: "Richard Huxton" To: "Txugo" , References: <45809a56.0107090919.177def5b@posting.google.com> Subject: Re: SQL - histogram Date: Wed, 11 Jul 2001 10:06:15 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 X-Archive-Number: 200107/139 X-Sequence-Number: 3931 From: "Txugo" > 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