How to select columns in which years are the same in Oracle?

2

I have a table called Clientes , and in it I have the following columns:

id_cliente
nm_cliente
dt_nascimento

I need to select and count all clients that were born in the same year. I already tried some things, but they do not return based on the same year, but on the same day, month and year.

My current query where it is not working looks like this:

SELECT dt_nascimento, count(*) FROM clientes
WHERE dt_nascimento = dt_nascimento
GROUP by dt_nascimento;

How can I select only based on the same year?

    
asked by anonymous 21.11.2017 / 00:37

1 answer

3

You must extract the year from the date field with the extract function. , you can use this query :

SELECT  EXTRACT(year FROM dt_nascimento) as ano, count(*) as quantidade
FROM clientes
GROUP by EXTRACT(year FROM dt_nascimento);

See the result:

    
21.11.2017 / 00:53