SQL按日期和月份选择查询顺序 [英] SQL select query order by day and month
本文介绍了SQL按日期和月份选择查询顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
今天假装是2月3日。
我有一张桌子:
CREATE TABLE devotion
(
id serial NOT NULL,
date timestamp without time zone
}
我有4条记录:
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 would return all records in the following order (ordered by date, but upcoming dates first, passed dates appended to 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 records have the same year. In fact, year is not important, only day and month are. If you can suggest a better structure, you are very welcome.
推荐答案
按date1>的情况排序now(),则为0,否则为0,否则为1个结束条件,date1
将给出3,4,1,2
will give order of 3,4,1,2
这篇关于SQL按日期和月份选择查询顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文