[英]Extracting year from a date timestamp in SQL
I am trying to convert a column in a database into a timestamp format, then I want to see the number of counts for each year. 我试图将数据库中的列转换为时间戳格式,然后想查看每年的计数数量。
I have: 我有:
SELECT
(column_name::date), count(*)
EXTRACT(YEAR FROM column_name)
FROM table
GROUP BY column_name;
'I get an error message that says no function matches the given name and argument types. '我收到一条错误消息,提示没有函数与给定的名称和参数类型匹配。 You might need to add explicit type casts.'
您可能需要添加显式类型转换。”
Is extract the wrong function? 提取错误的功能吗?
You probably want something like this if column_name
is timestamp 如果
column_name
是时间戳,则可能需要这样的内容
search for EXTRACT documentation 搜索EXTRACT文档
SELECT
EXTRACT(YEAR FROM column_name), count(*)
FROM table
GROUP BY EXTRACT(YEAR FROM column_name);
if column_name
is string you need to_timestamp() function 如果
column_name
是字符串,则需要to_timestamp()函数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.