----------一条SQL语句求解---------
表TBL
NAME GRADE
张三 100
张三 100
张三 80
张三 60
张三 60
李四 80
李四 60
李四 60
王五 60
...
...
求:统计GRADE为100时人数,统计GRADE为80时人数,统计GRADE为60时人数
限制:1:每个人只允许参与一次统计,如张三2条记录GRADE为100但只统计一条
2:若张三在GRADE为100被统计,则在GRADE为80和60时都不被统计(GRADE为80和60时不考虑张三)。
表TBL
NAME GRADE
张三 100
张三 100
张三 80
张三 60
张三 60
李四 80
李四 60
李四 60
王五 60
...
...
求:统计GRADE为100时人数,统计GRADE为80时人数,统计GRADE为60时人数
限制:1:每个人只允许参与一次统计,如张三2条记录GRADE为100但只统计一条
2:若张三在GRADE为100被统计,则在GRADE为80和60时都不被统计(GRADE为80和60时不考虑张三)。
解决方案 »
- 计算 字符串类型 的时间差
- 把另一台机的硬盘上oracle整个目录都copy到我本机上,两台机都装的是oracle9i,现在我想在我本机上恢复那台机的数据,请问有什么方法?
- 数据库 xml字段查询
- oracle9i数据恢复问题。急死了......
- Routine (test_proc) can not be resolved
- 请高手解决存储过程
- 一个关于在pb9中调用oracle9存储过程的问题?
- 怎么用才能使ORACLE数据库中的游标循环多次?
- create的问题
- 请问:Oracle怎么才能像SQL Server那样连续执行多条SQL语句,
- 疑惑一个例子,请较一下大家的想法
- jsp与oracle中日期型数据转换问题
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));
请高手尽量用效率高的算法,谢过
再次感谢楼上
from
(select name,max(grade) grade from tbl group by name) A
group by grade;
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