sql中2个表的字段完全相同,求其中某个字段的和

例如:学生交学费,分年交,表是根据年限建立的。每个表都是学号SNO,姓名SNAME,缴费sal,这个学费不是所有学生都一样的,现在想要看看2年来所有学生各交了多少费用。
恩 忘了个条件 就是只要查询学号在n和s之间的学生 学号是在另一个表c中,c表是学校分成各系的学生名册
这样写 select sno,sname,(a.sal+b.sal) as sal from a,b where a.sno=b.sno and a.no in(select sno from c where sno between 'n' and 's') and b.no in(select sno from c where sno between 'n' and 's') group by sno,sname,sal 提示列无效

第1个回答  2012-04-04
select a.sno,a.sname,(a.sal+b.sal) as sal from a,b where a.sno=b.sno追问

select sno,sname,(a.sal+b.sal) as sal from a,b where a.sno=b.sno and a.no in(select sno from c where sno between 'n' and 's') and b.no in(select sno from c where sno between 'n' and 's') group by sno,sname,sal 提示列无效

第2个回答  2012-04-03
select sno,sname,(a.sal+b.sal) sumsal from a,b where sno=sno;
第3个回答  2012-04-04
用union
select sno,sname,sum(sal)
from (select sno,sname,sal from a where sno in(select sno from c where sno between 'n' and 's')
union all
select sno,sname,sal from b where sno in(select sno from c where sno between 'n' and 's'))本回答被提问者采纳
相似回答
大家正在搜