View Full Version : how to write SQL to get the sum of Record in table?


jerry28ph
01-09-2009, 07:44 AM
Hi All,

I am doing a query on Call Log Sheet. Here's the fields:

Operator Int_Ext Calls
--------------------------
101 I
102 E
103 E
101 I
105 E
101 E
--------------------------

On Int_Ext Calls field, "I" denotes as Internal Call and "E" as External Calls. Please help me how to get the sum of Internal and External Calls with the specified Operator. Says For Operator 101 Internal Calls = 2 and External Calls = 1. Is there any SQL language that we can use to solve this?

Please I am asking your kindness.

Thank you.

pbaldy
01-09-2009, 07:51 AM
Try

SELECT Operator, Int_Ext Calls, Count(*) AS HowMany
FROM TableName
GROUP BY Operator, Int_Ext Calls

Brianwarnock
01-09-2009, 07:56 AM
If you want to get the 2 counts in one query then
SELECT Operator, sum(iif([Int_Ext Calls]="I",1,0)) as CountInternalCalls,sum(iif([Int_Ext Calls]="E",1,0)) as CountExternalCalls,
FROM TableName
GROUP BY Operator

Brian