Re: [SQL] group by range of values

2007-07-27 Thread Michael Glaesemann
2007/7/27, Carol Cheung <[EMAIL PROTECTED]>: db=# select * from tester order by birth_year; birth_year | salary + 1946 | 78000 1949 | 61000 What is the data type of the birth_year column? I'd suggest using date if you can, as what it is is a date with

Re: [SQL] group by range of values

2007-07-27 Thread Rodrigo De León
On 7/27/07, I wrote: > On 7/27/07, Carol Cheung <[EMAIL PROTECTED]> wrote: > > Something like: > > > > decade | average(salary) > > ---+- > >1940 | 69500 > >1950 | 5.33 > >1960 | 53000 > >1970 | 40333.33 > > CREATE TABLE tester ( > birth_year integer, >

Re: [SQL] group by range of values

2007-07-27 Thread Pavel Stehule
Hello you can use CASE like SELECT CASE WHEN birth_year BETWEEN 1940 AND 1949 THEN 1940 WHEN birth_year BETWEEN 1950 AND 1959 THEN 1950 WHEN birth_year BETWEEN 1960 AND 1969 THEN 1960 WHEN birth_year BETWEEN 1970 AND 1979 THEN 1979 END, AVG(salary) FROM tester GROUP BY 1 ORDER BY 1; R

Re: [SQL] group by range of values

2007-07-27 Thread Rodrigo De León
On 7/27/07, Carol Cheung <[EMAIL PROTECTED]> wrote: > Something like: > > decade | average(salary) > ---+- >1940 | 69500 >1950 | 5.33 >1960 | 53000 >1970 | 40333.33 CREATE TABLE tester ( birth_year integer, salary numeric(10,2) ); SELECT SUBSTRING(T

Re: [SQL] group by range of values

2007-07-27 Thread Jon Sime
Carol Cheung wrote: 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 | 5 1965 | 45000 1967 |

[SQL] group by range of values

2007-07-27 Thread Carol Cheung
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 | 5 1965 | 45000 1967 | 6 1968 |