我在 MS-Access 中有一个查询,我试图根据条件提取一些值,然后对结果求和。
SELECT SchedulingLog.UserID, SchedulingLog.Category, Sum(SchedulingLog.Value) AS Gain, Sum(SchedulingLog.Value) AS Used, [Gain]+[Used] AS [Left]
FROM SchedulingLog
GROUP BY SchedulingLog.UserID, SchedulingLog.Category, [Gain]+[Used]
HAVING ((
(SchedulingLog.Category) Like "DH*" Or
(SchedulingLog.Category) Like "Com*") AND
("Where[CatDetai]" Like "Gain*") AND
("Where[CatDetai]" Like "Used*")
);
有了这些数据SchedulingLog
...
Userid LogDate EventDate Category CatDetail Value
abc123 1-1-11 7-2-11 DH DH Used -1
abc123 1-1-11 7-4-11 DH DH Gain 1
...我希望我的查询给我这个结果集:
Userid Category Gain Used Left
abc123 DH 1 -1 0