Crosstab Query help

K

ken

Hello,

I have a table that has some fields openDate, closedDate,Site and callID. I
am trying to use a crosstab query to list the average time spent on calls
for each site. Below is the query I am using.
TRANSFORM Avg(calls.ClosedDate) AS AvgOfClosedDate
SELECT Format([opendate],' mm') AS [Month],
Count(DateDiff("d",[openDate],[ClosedDate])) AS Elapsed
FROM calls
WHERE (((calls.site)="OC") AND ((calls.ClosedDate) Is Not Null))
GROUP BY Format([opendate],' mm')
PIVOT DateDiff("d",[openDate],[ClosedDate]);

The results returned are:
Month Elapsed 4 26
03 2 38075 38075

What I need would be:
Month Total Avg
03 2 15

Any help would be appreciated as this is new to me.
Ken
 
D

Duane Hookom

I don't think you need a crosstab
SELECT Format([opendate],' mm') AS [Month], Count([OpenDate]) as TheTotal,
Avg(DateDiff("d",[openDate],[ClosedDate])) as TheAvg
FROM Calls
WHERE site="OC" AND ClosedDate Is Not Null
GROUP BY Format([opendate],' mm');
 
K

ken

That worked great. Thanks for all the help
Duane Hookom said:
I don't think you need a crosstab
SELECT Format([opendate],' mm') AS [Month], Count([OpenDate]) as TheTotal,
Avg(DateDiff("d",[openDate],[ClosedDate])) as TheAvg
FROM Calls
WHERE site="OC" AND ClosedDate Is Not Null
GROUP BY Format([opendate],' mm');

--
Duane Hookom
MS Access MVP
--

ken said:
Hello,

I have a table that has some fields openDate, closedDate,Site and
callID.
I
am trying to use a crosstab query to list the average time spent on calls
for each site. Below is the query I am using.
TRANSFORM Avg(calls.ClosedDate) AS AvgOfClosedDate
SELECT Format([opendate],' mm') AS [Month],
Count(DateDiff("d",[openDate],[ClosedDate])) AS Elapsed
FROM calls
WHERE (((calls.site)="OC") AND ((calls.ClosedDate) Is Not Null))
GROUP BY Format([opendate],' mm')
PIVOT DateDiff("d",[openDate],[ClosedDate]);

The results returned are:
Month Elapsed 4 26
03 2 38075 38075

What I need would be:
Month Total Avg
03 2 15

Any help would be appreciated as this is new to me.
Ken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Query on Duration 1
Totals query rework 1
Union query error 3
Last Question on Select Query 3
Select Query 4
Average Duration of time 1
PIVOT Question 6
Crosstab - Multiple values on each row 5

Top