tb1中 name:班级名称 , lb:班级类别
tb2中 bh:班机编号 , lb:班级类别
tb3中 bh:班机编号 , id :学号
tb4 中 store:考试成绩,id :学号
想要得出每个班级的总分:用如下的sql语句实现不了:
select name,sum(store)
from tb1 a, tb2 b, tb3 c,tb4 d
where a.lb=b.lband b.bh=c.bh and c.id=d.id
group by name
这样写的话会出现很多重复的记录,得不到真正的store。
因此考虑使用临时表来实现,是不是要生成2个临时表啊??
#temp1 name ,lb,bh
#temp2 bh,id,store
然后 temp1.bh=temp2.bh得到 name 和sum(store)
请问如何来写这个存储过程啊?
|