开发者

SQL - Count by range

开发者 https://www.devze.com 2023-02-06 08:52 出处:网络
How can I select the number of population by age group count ( 0->10) cou开发者_运维知识库nt ( 11->20)

How can I select the number of population by age group

count ( 0->10)
cou开发者_运维知识库nt ( 11->20)


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消