Re: how to sort a birthday list ? - Mailing list pgsql-sql

From Josh Berkus
Subject Re: how to sort a birthday list ?
Date
Msg-id 200206201703.52435.josh@agliodbs.com
Whole thread Raw
In response to how to sort a birthday list ?  (Michael Agbaglo <byteshifter@shifted-bytes.de>)
List pgsql-sql
Michael,

> SELECT *
> FROM Persons
> WHERE EXTRACT( YEAR FROM AGE(dateofbirth) ) < EXTRACT( YEAR FROM AGE(
> CURRENT_DATE+60, dateofbirth ) )
>
> ... but how do I sort the list ?

Easy:

SELECT person_name, person_department,  EXTRACT( YEAR FROM AGE(dateofbirth) )
as their_age
FROM Persons
WHERE EXTRACT( YEAR FROM AGE(dateofbirth) ) < EXTRACT( YEAR FROM AGE(
CURRENT_DATE+60, dateofbirth ) )
ORDER BY their_age, person_name

As an example.





--
-Josh Berkus



pgsql-sql by date:

Previous
From: Josh Berkus
Date:
Subject: Re: SQL performance issue with PostgreSQL compared to
Next
From: Josh Berkus
Date:
Subject: SQL Challenge: Skip Weekends