PostgreSQL从日期类型计算年龄

编程入门 行业动态 更新时间:2024-10-28 13:16:32
本文介绍了PostgreSQL从日期类型计算年龄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有下表:

CREATE TABLE public.employees ( employee_id integer NOT NULL, name text NOT NULL, date_of_birth date, address text, email text, CONSTRAINT employees_pkey PRIMARY KEY (employees_id), CONSTRAINT employees_email_key UNIQUE (email) )

我如何列出每个员工的姓名及其

How would I be able to list each employee's name with their age in the output?

谢谢。

推荐答案

使用date_part( )和age()函数

Use date_part() and age() functions

SELECT name text, date_part('year',age(date_of_birth)),* FROM public.employees

有关日期函数的文档,请参见 www.postgresql/docs/current/static/functions-datetime.html

See for documentation of date functions www.postgresql/docs/current/static/functions-datetime.html

更多推荐

PostgreSQL从日期类型计算年龄

本文发布于:2023-10-26 07:24:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1529472.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:年龄   日期   类型   PostgreSQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!