Skip to content
Advertisement

Name of customers who are of legal age (18 years) Postgresql

I have a question about how to return only customers over 18 years old. I’m just getting back from the customers

SELECT 
    custname,
    (2021 - part_date ('year', custdatebirth)) AS age
FROM 
    customers;

Advertisement

Answer

If you want to filter the rows, use a where clause. If you want to filter by age, you can use date comparisons:

where custdatebirth < current_date - interval '18 year'

Note that phrasing the condition this way makes it friendlier to indexes.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement