Suppose today is February 3rd.
And I have a table:
CREATE TABLE devotion
(
id serial NOT NULL,
date timestamp without time zone
}
And I have 4 entries:
id date
1 2013-01-01
2 2013-02-02
3 2013-03-03
4 2013-04-04
I want to build a select query that will return all records in the following order (sorted by date, but upcoming dates first, date is at the end of the list):
id date
3 2013-03-03 (upcoming dates first)
4 2013-04-04
1 2013-01-01 (passed dates appended to the end of the list)
2 2013-02-02
All entries have the same year. In fact, the year is not important, only the day and month. If you can offer a better structure, you are very pleased.
source
share