I have a query in MS-Access that I am trying to pull some values based on a condition, then sum the results.
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*")
);
With these data in 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
… I want my query to give me this result set:
Userid Category Gain Used Left
abc123 DH 1 -1 0
The following SQL returns what you asked for based on testing with your sample data in Access 2007.
However, if you don’t actually need to see the separate values for
GainandUsed, it would be simpler to do it this way: