I have the following table:
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?
Thanks.
解决方案
Use date_part() and age() functions
SELECT name text, date_part('year',age(date_of_birth)),* FROM public.employees