Add comparatives to grouped totals queries

KirRoyale

Registered User.
Local time
Today, 16:59
Joined
Apr 22, 2013
Messages
61
I have a totals query of phone call charges by phone number and I want to show a ‘budget’ amount for each number (same amount for all) and a variance against that budget.
Could someone please advise how I can do this at the grouped (phone number) level rather than at the individual call level?
Please see current query below:
SELECT Call1CurrentTbl.電話番号(MSN, Sum(Call1CurrentTbl.料金) AS 料金OfSum
FROM Call1CurrentTbl
GROUP BY Call1CurrentTbl.電話番号(MSN, Call1CurrentTbl.[レコード区分], Call1CurrentTbl.表示区分
HAVING (((Call1CurrentTbl.[レコード区分])=2) AND ((Call1CurrentTbl.表示区分)=10));
 
I can't see what is actually going on because of the kanjii characters but it looks like you are grouping by more columns than you are selecting. Also, your Having clause may need to be a WHERE clause if it is limiting the records you want to summarize. Where is applied BEFORE aggregation and does not need to select the columns used for criteris but Having is applied AFTER aggregation and is normally used as criteria against an aggregated value.

So Select EmpID, Sum(Expenses) From x WHERE Dept = 22 Group by EmpID
OR
Select EmpID, Sum(Expenses) From x WHRE Dept = 22 Group by EmpID Having Sum(Expensed) > 1000;
 
Thank you very much. That clears things up.
 

Users who are viewing this thread

Back
Top Bottom