Re: group by range of values

From: Rodrigo De León <rdeleonp(at)gmail(dot)com>
To: "Carol Cheung" <cacheung(at)consumercontact(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: group by range of values
Date: 2007-07-27 19:28:56
Message-ID: a55915760707271228l76711711l1ae9e033db22e9d9@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On 7/27/07, Carol Cheung <cacheung(at)consumercontact(dot)com> wrote:
> Something like:
>
> decade | average(salary)
> -------+-----------------
> 1940 | 69500
> 1950 | 53333.33
> 1960 | 53000
> 1970 | 40333.33

CREATE TABLE tester (
birth_year integer,
salary numeric(10,2)
);

SELECT
SUBSTRING(TO_CHAR(BIRTH_YEAR,'FM9999') FROM 1 FOR 3)||'0'
AS DECADE
, AVG(SALARY) AS AVG_SALARY
FROM TESTER
GROUP BY
SUBSTRING(TO_CHAR(BIRTH_YEAR,'FM9999') FROM 1 FOR 3)||'0'
ORDER BY DECADE;

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Pavel Stehule 2007-07-27 19:30:23 Re: group by range of values
Previous Message Jon Sime 2007-07-27 19:25:46 Re: group by range of values