I don't know if I can explain what I want, but I have the following table:
Año | Primero | Segundo | Tercero
2021 11 13 44
2021 34 21 11
2021 11 34 13
The numbers will be random and from 1 to 99. I would like to count the total numbers in the columns. Example:
Número 11: 3
Número 13: 2
Número 34: 2
Is it possible to do this with SQL using MySQL? The programming language I am using is PHP. I tried using COUNT():
SELECT COUNT(Primero) AS P, COUNT(Segundo) AS S, COUNT(Tercero) AS T FROM tabela;
But I don't think that's the case as it would bring the total table count and not the records I need.
What you could do is join the three columns into one and only then count the amounts of each value:
The
group by
is applied to a subquery where we join all the values of each row using theunion all
.