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.