Make a Postgresql bank count

0

Good morning.

I wanted to make a select in my bank and return the number of registrations.

Example:

tb_client; column: dt_cadastro;

In the dt_cadastro column I have this:

2000-01-20
2001-10-05
1990-11-09
1990-07-16
1990-08-10

I wanted to do a select like this:

SELECT dt_cadastro, count(dt_cadastro)
FROM tb_cliente
WHERE dt_cadastro < 2000
GROUP BY dt_cadastro

I mean, I want to know how many are less than 2000 and I'm not getting it.

Following the suggestion of @Motta , I used this:

SELECT dt_cadastro , count(dt_cadastro )
FROM tb_cliente
WHERE  Extract(year from dt_cadastro ) = Extract(year from '1990-12-31'::DATE)
GROUP BY dt_nasc

Only the result was:

"1990-01-01";1
"1990-08-02";1
"1990-08-08";1

I needed the 3 value to appear, is it possible?

    
asked by anonymous 23.03.2017 / 14:03

2 answers

0

The solution to your question is correct, however in SELECT you should only put the options you want to "see", see SQL below if it's what you really need:

SELECT COUNT(dt_cadastro) -- no select vai somente a informação que você quer ver
  FROM tb_cliente
 WHERE EXTRACT(YEAR FROM dt_cadastro) = EXTRACT(YEAR FROM '1990-12-31'::DATE)
 GROUP BY dt_nasc
    
14.06.2017 / 15:11
-1

Solution found:

  

SELECT COUNT (*) FROM tb_client WHERE EXTRACT (YEAR FROM dt_cadastro) =   1980;

    
23.03.2017 / 17:55