这是我第一次请求你的帮助,
实际上我必须创建一个查询,并为它做了一个类似的例子.我有两张桌子,
Report (ReportID, Date, headCount)
Production(ProdID, ReportID, Quantity)
Run Code Online (Sandbox Code Playgroud)
我的问题是使用此查询,我得到了错误的结果,
SELECT
Report.date,
SUM(Report.HeadCount) AS SumHeadCount,
SUM(Production.Quantity) AS SumQuantity
FROM
Report
INNER JOIN
Production ON Report.ReportID = Production.ReportID
GROUP BY
Date
ORDER BY
Date
Run Code Online (Sandbox Code Playgroud)
我想有些行不止一次,请你帮个忙吗?
编辑
如果我运行查询以获得按天分组的人数总和,我得到:
date Headcount
7/2/2012 1843
7/3/2012 1802
7/4/2012 1858
7/5/2012 1904
Run Code Online (Sandbox Code Playgroud)
我也得到了生产数量:
2012-07-02 8362
2012-07-03 8042
2012-07-04 8272
2012-07-05 9227
Run Code Online (Sandbox Code Playgroud)
但是当我结合两个查询时,我得到的是假的,我预计7月2日8362数量对1843年,但我得到:
day TotalHeadcount totalQty
7/2/2012 6021 8362
7/3/2012 7193 8042
7/4/2012 6988 8272
7/5/2012 7197 9227
Run Code Online (Sandbox Code Playgroud)