选择日期字段在给定月份和年份中的行 [英] Select lines whose date-field is in a given month and year
本文介绍了选择日期字段在给定月份和年份中的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的SQL表如下:
id (int) | date (date) | text1 (varchar) | text2 (varchar)
我想选择日期适合给定月份和年份的行,而不管那天。
在选择语句中,月份和年份均以整数形式给出。
所以缺少的是哪里子句。也许 extract()
是我想要的东西,但是我不知道如何将它与两个整数一起使用,例如 2011
和 02
。
I want to select the lines whose date suits a given month and year, regardless of the day.
Both month and year are given in the select-statement as integers.
So the missing thing is the where-clause. Perhaps extract()
is the thing I'm looking for, but I don't know how to use it with the two integers, e.g. 2011
and 02
.
推荐答案
您可以使用提取:
SELECT * FROM yourtable
WHERE EXTRACT(month FROM "date") = 2
AND EXTRACT(year FROM "date") = 2011
但是情况下,您也可以这样做:
But in this case you could also do this:
SELECT * FROM yourtable
WHERE "date" >= '2011-02-01' AND "date" < '2011-03-01'
这篇关于选择日期字段在给定月份和年份中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文