Re: group by range of values - Mailing list pgsql-sql

From Rodrigo De León
Subject Re: group by range of values
Date
Msg-id a55915760707271228l76711711l1ae9e033db22e9d9@mail.gmail.com
Whole thread Raw
In response to group by range of values  (Carol Cheung <cacheung@consumercontact.com>)
Responses Re: group by range of values  ("Rodrigo De León" <rdeleonp@gmail.com>)
List pgsql-sql
On 7/27/07, Carol Cheung <cacheung@consumercontact.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;


pgsql-sql by date:

Previous
From: "Pavel Stehule"
Date:
Subject: Re: group by range of values
Next
From: "Rodrigo De León"
Date:
Subject: Re: group by range of values