您好,欢迎来到醉满楼美食网。
搜索
您的当前位置:首页数据库查询SQL_MySQL

数据库查询SQL_MySQL

来源:醉满楼美食网


1)现在的情况是这样的:有一个表 testtbl( id int, name varchar, level int, age int) ; 根据level的取值分为三个级别:高,中,低。

 现在要统计每个age中,高、中、和低级别的数目。即通过age作group by,但在每个age值内,还要按level取值统计各级别的记录数。

解决方案:

select age, (select count(*) from testtbl t2 where t2.age=t1.age and level

(select count(*) from testtbl t2 where t2.age=t1.age and level =?)as mid,

(select count(*) from testtbl t2 where t2.age=t1.age and level >?)as high

from testtbl t1 group by age;

Copyright © 2019- zuimanlou.com 版权所有

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务