2

How can I select the number of population by age group

count ( 0->10)
count ( 11->20)
RichardTheKiwi
  • 102,799
  • 24
  • 193
  • 261
Chaabelasri E.
  • 150
  • 3
  • 15
  • 1
    possible duplicate of [In SQL, how can you "group by" in ranges?](http://stackoverflow.com/questions/232387/in-sql-how-can-you-group-by-in-ranges) – RichardTheKiwi Jan 25 '11 at 10:14
  • I found this http://stackoverflow.com/questions/3247630/mysql-group-by-age-range-including-null-ranges might also be a solution to count the group-by age-range –  Aug 04 '11 at 19:13

2 Answers2

4

There are other question about the same, you can found the solution on: In SQL, how can you "group by" in ranges?

The syntax is valid for mysql too.

Community
  • 1
  • 1
Borja
  • 2,148
  • 18
  • 21
3

Try this:

SELECT FLOOR(age / 10), COUNT(*)
FROM yourTable
GROUP BY FLOOR(age / 10)

Manipulate the age / 10 expression to get the exact ranges. This will return 0 for ages 0-9, 1 for ages 10-19, etc.

eumiro
  • 194,053
  • 32
  • 286
  • 259