Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 32C469FB279 for ; Fri, 27 Jul 2007 16:05:31 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 59373-09 for ; Fri, 27 Jul 2007 16:05:28 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from mail.consumercontact.com (mail.consumercontact.com [209.167.202.12]) by postgresql.org (Postfix) with ESMTP id 9182B9FB266 for ; Fri, 27 Jul 2007 16:05:28 -0300 (ADT) Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.consumercontact.com (Postfix) with ESMTP id B7F785904E4 for ; Fri, 27 Jul 2007 15:05:27 -0400 (EDT) X-Virus-Scanned: amavisd-new at consumercontact.com Received: from mail.consumercontact.com ([127.0.0.1]) by localhost (mail.consumercontact.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PfzkSGFZyHjP for ; Fri, 27 Jul 2007 15:05:27 -0400 (EDT) Received: from [192.168.1.47] (mordred.consumercontact.com [192.168.1.47]) by mail.consumercontact.com (Postfix) with ESMTP id 5911B5904BB for ; Fri, 27 Jul 2007 15:05:27 -0400 (EDT) Message-ID: <46AA41EC.8050101@consumercontact.com> Date: Fri, 27 Jul 2007 15:05:16 -0400 From: Carol Cheung User-Agent: Thunderbird 1.5.0.12 (Windows/20070509) MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: group by range of values Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200707/170 X-Sequence-Number: 28905 Hello, Here's my table: db=# select * from tester order by birth_year; birth_year | salary ------------+-------- 1946 | 78000 1949 | 61000 1951 | 58000 1953 | 56000 1958 | 52000 1962 | 50000 1965 | 45000 1967 | 60000 1968 | 57000 1970 | 47000 1972 | 32000 1973 | 42000 (12 rows) How can I display the average salary grouped by decade of birth year? That is, is it possible to display the average salary of those born in the 1940's, the average salary of those born in the 1950's, average salary of those born in the 1960's, and those born in the 1970's, all in one result table? Something like: decade | average(salary) -------+----------------- 1940 | 69500 1950 | 53333.33 1960 | 53000 1970 | 40333.33 Thanks in advance, C