我有根据各种标准汇总的数据,但每个ID代码都有多个日期记录。如果日期是最近的日期,我无法弄清楚如何告诉Access只有SUM。
因此,对于给定的IDcode(API number
),查询将对所有日期的所有满足所列条件的数据进行求和。
我想限制它只是查看最近的日期 - 但每条记录都有不同的最近日期(JobEndDate
)。
任何想法?我对Access / SQL比较陌生。
SELECT
dbo_RegistryUpload.APINumber,
Sum(dbo_RegistryUploadIngredients.PercentHFJob) AS 4070,
Max(dbo_RegistryUpload.JobEndDate) AS MaxOfJobEndDate
FROM
(dbo_RegistryUpload INNER JOIN dbo_RegistryUploadPurpose
ON dbo_RegistryUpload.pKey = dbo_RegistryUploadPurpose.pKeyRegistryUpload)
INNER JOIN dbo_RegistryUploadIngredients
ON dbo_RegistryUploadPurpose.pKey = dbo_RegistryUploadIngredients.pKeyPurpose
WHERE (((dbo_RegistryUploadPurpose.TradeName) Like "*40/70*"))
OR (((dbo_RegistryUploadPurpose.TradeName) Like "*40-70*"))
GROUP BY dbo_RegistryUpload.APINumber
HAVING (((dbo_RegistryUpload.APINumber) Like "42*"))
OR (((dbo_RegistryUpload.APINumber) Like "42*"));
这是我的数据(已按日期汇总)
APINumber 4070 JobEndDate
42003045490000 39.30987804 18-Feb-15
42003045490000 7.56203693 24-Feb-15
42003046050000 6.334731543 05-Jun-15
42003317940000 1.624367441 24-Nov-14
42003317940000 2.359888624 25-Nov-14
42003318510000 4.644843464 22-Jul-13
42003322540000 2.476440141 04-Dec-14
我想要的输出是以下
APINumber 4070 JobEndDate
42003045490000 7.56203693 24-Feb-15
42003046050000 6.334731543 05-Jun-15
42003317940000 2.359888624 25-Nov-14
42003318510000 4.644843464 22-Jul-13
42003322540000 2.476440141 04-Dec-14
答案 0 :(得分:0)
避免尝试在一个查询中执行所有操作。
创建新查询,从每个MAX JobEndDate
的源数据中选择APINumber
。
将此加入现有查询(JobEndDate
和APINumber
),仅列出最新JobEndDate
的行。