【发布时间】:2012-08-30 00:47:53
【问题描述】:
我有三个表第一个“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
前两个给了我完美的值,但第三个小说给出了错误,没有显示名字。
【问题讨论】:
-
您能否展示一些您的表格中的数据以及您期望的结果?