Number of SQL statements grouped by age group

Source: Internet
Author: User


The SQL statement counts the number of people by age group. Java code www.2cto.com create table # t (Uname varchar (10), age int) insert # t select 'Ah', 19 union all select 'info ', 23 union all select 'baby', 31 union all select 'hour', 21 union all select 'mimi', 6 select nnd as 'age', count (*) as 'number of people' from (select case when age> = 1 and age <= 10 then'1-10' when age> = 11 and age <= 20 then'11-20' when age> = 21 and age <= 30 then '21-30' when age> = 31 and age <= 40 then '31-40' end as nnd, uname from # t) a group by nnd
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.