Student 表name varchar(50),age int(3) ,查询数据库以年龄分区,查询每个区的人数总数,显示效果:
11 至 20 岁 21 至 30 岁 31 至 40岁
5 10 10
SQL语句:
select * from (select * from (select count(*) as '11 至 20岁' from student where age >=10 and age <=20) as a join (select count(*) as '21 至 30岁' from student where age >=21 and age <=30) as b) as c join ( select count(*) as '31 至40岁' from student where age >=31 and age <=40 ) as d