本文介绍了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从日期类型计算年龄
发布评论