日期:2014-05-16  浏览次数:20804 次

求一句sql.......................
2个表,一个进货表-> ins,一个销售表-> outs,分别2个字段,如下
ins:
编号 id num
1 a 10
2 a 20
3 a 5
4 b 10
5 b 15
6 c 20
7 c 16
outs:
编号 id num
1 a 4
2 a 7
3 a 3
4 b 5
5 b 6
6 c 3
7 c 2

请问
1:如何选出ins表中id=a的所有记录的num字段的和
2:如何选出2个表中id=a的所有记录的num字段的和

------解决方案--------------------
1
select sum(num) from ins where id=a
2
select sum(num)+(select sum(num) from outs where id=a) from ins where id=a