create table test(name varchar2(10),
score int);
insert into test values ('aa',89);
insert into test values ('bb',45);
insert into test values ('cc',67);
insert into test values ('dd',25);
insert into test values ('ee',45);
insert into test values ('ff',68);
insert into test values ('gg',78);
insert into test values ('hh',23);
执行第一个select sum(case when score>60 then 1 else 0 end) as 大于60分,
sum(case when score<60 then 1 else 0 end) as 小于50分
from test;
结果
执行第二个select '大于60分',count(*) from test where score>60
union all
select '小于50分',count(*) from test where score<50
结果