1
I have a database where the values are organized more or less as follows:
id | produto | data com registro de venda
----------------------------------------------
1 | Prod1 | 17/09/2019
2 | Prod1 | 17/09/2019
3 | Prod2 | 17/09/2019
4 | Prod2 | 14/09/2019
5 | Prod1 | 12/09/2019
6 | Prod1 | 12/09/2019
7 | Prod1 | 17/09/2019
8 | Prod1 | 14/09/2019
9 | Prod3 | 17/09/2019
10 | Prod3 | 17/09/2019
11 | Prod1 | 11/09/2019
12 | Prod1 | 15/09/2019
Information I would like to get
Prod1 = 5 dias com vendas registradas (ignorando os dias repetidos)
Prod2 = 2 dias com vendas registradas (ignorando os dias repetidos)
Prod3 = 1 dia com vendas registradas (ignorando os dias repetidos)
Show what you have tried, if you tried something and gave error count, put in the body of the question
– Tmilitino
I haven’t tried anything yet. I’ve just learned to make simple appointments. Situations that require more complex results, as is the case of the question, I still do not know how to do.
– hofmanng96
Dude. You know how to use
group by
and functions ofcount
andunique
– Tmilitino
I think what you want is something like: SELECT product, COUNT(DISTINCT data) FROM sua_tabela GROUP BY product; The Postgresql documentation is very good, see it: https://www.postgresql.org/docs/current/index.html
– anonimo
@anonimo, that’s right! I’m just in doubt if he wants with the texts, as in the return example
– Tmilitino
If it wanted with the text it would be: SELECT product, ' = ', COUNT(DISTINCT data), ' days with registered sales (ignoring repeat days)' FROM sua_table GROUP BY product;
– anonimo
Yesterday I had managed to settle using the DISTINCT. Thank you.
– hofmanng96