可能重复:
如何从两个表中获取总和?
我有三个表第一个“products第二个” items“第三个” sales“
第一个和第二个表有相同的列(' code',' quantity')但是第三个表有(' code',' name')现在我想要第一和第二个的总和数量但也想从第三个表中获取代码相同的名称。检查我的代码
Select code, sum(qtd),name
from ( select a.code, a.qtd from product a
union all select b.code, b.qtd from items b
union all select c.name from sales c where b.code=c.code
)
group by code
前两个给了我完美的价值观,但第三个小说给出了错误,也没有显示名字。