0
Good morning .
I wanted to select in my bank and return the number of registered .
Example:
tb_client; column: dt_register;
in the dt_register column I have this:
2000-01-20
2001-10-05
1990-11-09
1990-07-16
1990-08-10
I wanted to make 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.
Following the suggestion of @Motta, 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 value to appear 3, it is possible?
WHERE Extract(year from dt_cadastro) < 2000 https://www.postgresql.org/docs/9.6/static/functions-datetime.html
– Motta
@Motta I will edit my question added your suggestion.
– Vilma
Try it this way
SELECT count(dt_cadastro )
FROM tb_cliente
WHERE Extract(year from dt_cadastro ) = Extract(year from '1990-12-31'::DATE)
GROUP BY dt_nasc
– R.Santos
@R.Santos did not give... appeared 1 1 1
– Vilma
Change group by to
Group by dt_cadastro
sees what the– R.Santos
@Vilma It worked out?
– R.Santos
@R.Santos also does not. I managed using this: SELECT COUNT(*) FROM tb_client WHERE EXTRACT(YEAR FROM dt_cadastre) = 1980; Now I’ll see how to use this with the Hibernate criteria.
– Vilma
@Vilma try it this way then
select count(*) from tb_cliente where dt_cadastro < '1999-12-31'
I tested it here in my database and it worked out, if it works out just let me know– R.Santos
@R.Santos, it didn’t work. I’m using, as I said earlier: SELECT COUNT(*) FROM tb_client WHERE EXTRACT(YEAR FROM dt_cadastre) = 1980; and it’s working the way I want it to. I will just convert this to the Hibernate criteria.
– Vilma
Strange, in my database Postgresql worked, bringing only the value of
Count
, but it worked out that much better– R.Santos