表如下:
表A 表B
------------------- ----------------------
teacher|student student|classname
------------------- ----------------------
t_a |blue blue |math
------------------- ----------------------
t_a |red blue |english
------------------- ----------------------
t_b |green red |histroy现在要统计出每个teacher有几个学生,及这些学生总共选得课有多少。请教各位大虾了~想得到的结果是
-------------------
teacher|student|classname
-------------------
t_a |2 |3
-------------------
t_b |1 |0
表A 表B
------------------- ----------------------
teacher|student student|classname
------------------- ----------------------
t_a |blue blue |math
------------------- ----------------------
t_a |red blue |english
------------------- ----------------------
t_b |green red |histroy现在要统计出每个teacher有几个学生,及这些学生总共选得课有多少。请教各位大虾了~想得到的结果是
-------------------
teacher|student|classname
-------------------
t_a |2 |3
-------------------
t_b |1 |0
解决方案 »
- 如何查询一个表的 所有列名,注释,主键情况,一个select
- 结果出现‘悲哀’ 期待高人指点
- 使用 create table xxx as 时,怎么转换 varchar2(10) 为 number(10)
- 关于oracle sql developer
- TNSLSNR 启动成功后马上自动关闭是什么问题啊
- 合并查询的简单问题
- 查询可以,但写成过程就出错。创建过程失败……
- oracle8i中在sql plus worksheet中执行脚本后,在结果窗口中显示的中局全部是乱码?
- 关于范式的问题,在线等候,很急,谢谢
- 呀呼!! google又能上啦! 散点分啦
- 怎么最快速的查找一个表里有,但另一个表里没有的数据?
- 这样设计的数据库,请给个意见
,(select count(classname) from b where b.student in(select student from a alias2 where alias2.teacher=a.teacher) )
from a
group by student
)
where a.student = c2
group by a.teacher
create table student(
student varchar2(10),
classname varchar2(10)
);create table teacher(
teacher varchar2(10),
student varchar2(10)
);insert into student values('blue','math');
insert into student values('blue','english');
insert into student values('red','histroy');insert into teacher values('t_a','blue');
insert into teacher values('t_a','red');
insert into teacher values('t_b','green');commit;-----------------sql---------------------- select zz.ttea as teacher,zz.t_cou as student,sum(yy.s_class) as classname
from (
select t.teacher ttea,count(t.student) as t_cou
from teacher t
group by t.teacher
)zz,
(select t.teacher stea,nvl(s.student,t.student) as stu_name,count(s.classname) as s_class
from teacher t,student s
where t.student = s.student(+)
group by t.teacher,t.student,s.student
)yy
where zz.ttea = yy.stea
group by zz.ttea,zz.t_cou;
--------------------result---------------------TEACHER STUDENT CLASSNAME
---------- ---------- ----------
t_a 2 3
t_b 1 0
group by student
)
where a.student = c2(+)
group by a.teacher
(select teacher ,tablea.student as student ,class from
tableb,tablea where tablea.student=tableb.student(+))a
group by a.teacher;这是我的sql 呵呵也通过了