2

我有两张表,例如 ONE 和 TWO,我的表更大且结构不同,但有些字段重合。

在此处输入图像描述

我怎样才能得到表QUERY?

我可以只用一个带有 GROUP 和 SUM 的表来完成,但是如何在 QUERY 中添加最后一列?可能吗?

SELECT Date, SUM(Apples), SUM(Oranges) FROM One
GROUP BY Date
4

2 回答 2

0
SELECT one.Date, one.place, SUM(Apples), SUM(Oranges), SUM(Grapes) 
FROM One left join Two on one.place = two.place and one.date = two.date
GROUP BY one.date, one.place

将返回第一个表中的所有位置和正确的计数

于 2013-11-04T18:16:21.750 回答
0
SELECT Date, one.place, SUM(Apples), SUM(Oranges), SUM(Grapes) 
FROM One left join Two on one.place = two.place and one.[Date] = two.[Date]
GROUP BY Date
于 2013-11-04T18:17:38.107 回答