怎么写这个SQL语句呢?
请教下我想这样,怎么写SQL语句呢?
select a.字段1+b.字段2-c.字段3 as 数量 from a,b,c
其中b.字段2又是这样:
select SUM(数量) where a.名称=b.名称
c.字段3:
select SUM(数量) where a.名称=c.名称
也就是说b.字段2,c.字段3分别是按a.名称在b,c中查找相同名称的数量累加的值..
------解决方案--------------------select a.name1,sum(a.num+b.num-c.num) as num
from a
inner join b on a.name1=b.name2
inner join c on a.name1=c.name3
group by a.name1
------解决方案--------------------select a.name1,sum(a.num+b.num-c.num) as num
from a
left join b on a.name1=b.name2
left join c on a.name1=c.name3
group by a.name1