SQL 在 PostgreSQL 中按月选择

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8863156/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 14:00:56  来源:igfitidea点击:

Selecting by month in PostgreSQL

sqlpostgresqldate

提问by aulia

I want to select rows according to the month of a dateor timestampcolumn like this:

我想根据 adatetimestamp列的月份选择行,如下所示:

SELECT id, name,?birthday 
FROM employee.person 
WHERE Month(birthday) > 10;

But I only get error messages in PostgreSQL.
How can this be done?

但我只在 PostgreSQL 中收到错误消息。
如何才能做到这一点?

回答by k.m

You can use EXTRACTfunction, like this:

您可以使用EXTRACT函数,如下所示:

SELECT id, name, birthday FROM employee.person 
WHERE EXTRACT(MONTH FROM birthday) > 10;

Your problem comes from the fact that there is no such thing as Monthfunction in PostgreSQL. Check online documentation hereto see what you can get instead. Extractshould be enough.

您的问题来自这样一个事实,即MonthPostgreSQL 中没有函数这样的东西。在此处查看在线文档以了解您可以获得什么。Extract应该够了。