3

How can I select the number of population by age group

count ( 0->10)
count ( 11->20)
RichardTheKiwi
  • 105,798
  • 26
  • 196
  • 262
Chaabelasri E.
  • 170
  • 4
  • 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

5

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,188
  • 1
  • 18
  • 21
4

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
  • 207,213
  • 34
  • 299
  • 261