简体   繁体   English

PostgresSQL数据库具有日期字段,我希望除日期列以外的所有数据仅作为年份

[英]PostgresSQL database has date field, I want all data but the date column as year only

I have data that has a date column in the full format but would like the output to only represent the year. 我的数据具有完整格式的日期列,但希望输出仅表示年份。

eg: from 例如:来自

SELECT * FROM tablename;

I want something like: 我想要类似的东西:

SELECT * FROM tablename WITH 'newdatefield' as SELECT EXTRACT(YEAR FROM TIMESTAMP 'datefield'); 

I'm not great at SQL - I remember that something like this can be done but can't find how to do it again. 我不太擅长SQL-我记得可以做类似的事情,但是找不到再次做的方法。

我认为您正在考虑这一点:

SELECT EXTRACT(YEAR from datefield), The, Other, Fields, You, Want FROM tableName

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM