1
How does the consultation to know the total number of people in the age range from 0 to 5 years, and if you do not have any child with a certain age, enter 0;
select idade, count(*) as qtd from pessoa group by idade order by idade
example of the current problem
+-----------+--------+
| idade | qtd |
+-----------+--------+
| 0 | 3 |
+-----------+--------+
| 3 | 7 |
+-----------+--------+
| 5 | 11 |
+-----------+--------+
Example of how I need the data
+-----------+--------+
| idade | qtd |
+-----------+--------+
| 0 | 3 |
+-----------+--------+
| 1 | 0 |
+-----------+--------+
| 2 | 0 |
+-----------+--------+
| 3 | 7 |
+-----------+--------+
| 4 | 0 |
+-----------+--------+
| 5 | 11 |
+-----------+--------+
Friend, but I need you to return 0 if there are no people that age, that’s the problem.
– Douglas
see if solve, this solution was made in sql server, but the idea is the same for mysql.
– Marco Souza