SQL Postgresql 查询当前年份
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35704412/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Postgresql query current year
提问by user2239318
I need to see only the current year rows from a table.
我只需要查看表格中的当前年份行。
Would it be possible filter a timestamp column only by current year parameter, is there some function that can return this value?
是否可以仅通过当前年份参数过滤时间戳列,是否有可以返回此值的函数?
SELECT * FROM mytable WHERE "MYDATE" LIKE CURRENT_YEAR
回答by MyBrainHurts
In PostgreSQL you can use this:
在 PostgreSQL 中你可以使用这个:
SELECT * FROM mytable WHERE date_part('year', mydate) = date_part('year', CURRENT_DATE);
The date_part function is available in all PostgreSQL releases from current down to 7.1 (at least).
date_part 函数在所有 PostgreSQL 版本中都可用,从当前版本到 7.1(至少)。
回答by Han Arantes
SELECT * FROM mytable WHERE myYear = YEAR(CURDATE())
The above code works for sql!
上面的代码适用于sql!