时间:2021-07-01 10:21:17 帮助过:23人阅读
现在要统计每个age中,高、中、和低级别的数目。即通过age作group by,但在每个age值内,还要按level取值统计各级别的记录数。
解决方案:
select age, (select count(*) from testtbl t2 where t2.age=t1.age and level )as low,
(select count(*) from testtbl t2 where t2.age=t1.age and level and level >=?)as mid,
(select count(*) from testtbl t2 where t2.age=t1.age and level >?)as high
from testtbl t1 group by age;