SQL - 如果只给出出生年份,如何填充年龄列?

问题描述 投票:0回答:0

数据只有出生年份列,标记为

year_birth

我添加了一个年龄列,但现在我想向此列添加值,以通过减去当前年份中的值来显示年龄

year_birth
列中的值。

“出生年份”“年龄” 1970
1961
1958
1967
1989
1958
1954
1967
1954
1954

此查询返回语法错误

-- Update Age column

update marketing_data
set age = DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(),year_birth)), '%Y') 
 + 0
ERROR:  function datediff(timestamp with time zone, integer) does not exist
LINE 4: set age = DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(),year_birth)),...
                                        ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts. 

SQL state: 42883
Character: 77
sql pgadmin-4
© www.soinside.com 2019 - 2024. All rights reserved.