日期:2014-05-17 浏览次数:20712 次
select count(1) from (select distinct name, grade from tbl where grade = 100); select count(1) from (select distinct name, grade from tbl a where a.grade = 80 and not exists (select name from tbl b where grade = 100 and a.name = b.name)); select count(1) from (select distinct name, grade from tbl a where a.grade = 60 and not exists (select name from tbl b where grade in (100,80) and a.name = b.name));
------解决方案--------------------
select grade,count(1) num
from
(select name,max(grade) grade from tbl group by name) A
group by grade;
------解决方案--------------------
with tbl as (
select 'a' name ,100 grade from dual
union
select 'a' name ,80 grade from dual
union
select 'b' name ,60 grade from dual
)select sum(case a.GRADE when 100 then 1 else 0 end) ,sum(case a.GRADE when 80 then 1 else 0 end),sum(case a.GRADE when 60 then 1 else 0 end)
from
(select max(GRADE) GRADE,NAME
from tbl
group by NAME
) a
------解决方案--------------------