Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Get Total and Averge Query

Author  Topic 

ahmedpower
Starting Member

6 Posts

Posted - 2013-01-06 : 07:55:15
Hi SQL Team

I am really straggle to get the total and average for any Query as well I tried with union all keywords for the below query

Select CT.EnterpriseName,
Sum(ISNULL(CTHH.CallsOfferedHalf,0)) CallOfferedMonthly,
Sum(ISNULL(CTHH.CallsAnsweredToHalf,0)) CallAnsweredMonthly,
Sum(ISNULL(CTHH.RouterCallsAbandQToHalf,0)) CallsAbandMonthly,
Avg(case
when CTHH.CallsAnsweredToHalf=0 or CTHH.CallsAnsweredToHalf is null then 0
else
ISNULL(CTHH.TalkTimeHalf,0)/CTHH.CallsAnsweredToHalf
end) as AvgTalkTimeMonthly,
Avg( case
when CTHH.RouterCallsAbandQToHalf=0 or CTHH.RouterCallsAbandQToHalf=null then 0
else
ISNULL(CTHH.CallDelayAbandTimeToHalf,0)/CTHH.RouterCallsAbandQToHalf
end) as AvgAbandWaitTimeMonthly,
Avg(case
when CTHH.CallsAnsweredToHalf=0 or CTHH.CallsAnsweredToHalf is null then 0
else
ISNULL(CTHH.AnswerWaitTimeHalf,0)/CTHH.CallsAnsweredToHalf
end) as AvgAnswerWaitTimeMonthly,
Avg(ISNULL(CTHH.ServiceLevelHalf,0)) ServiceLevelMonthly

from
Call_Type CT
inner join
Call_Type_Half_Hour CTHH on CT.CallTypeID = CTHH.CallTypeID
and DateTime Between '2013-01-01 00:00:00' and '2013-01-05 23:59:59'
where CT.CallTypeID IN (5006, 5007, 5012, 5011, 5008, 5009)
Group by CT.EnterpriseName



Please advise only how to get total and average as i will really Appricate your support.



Ahmed Soliman

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-01-06 : 10:13:16
the logic looks fine. can you explain what you mean by total and average ot working? give some sample data and explain the expected and current obtained values

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

jardrake
Starting Member

3 Posts

Posted - 2013-01-07 : 02:42:21
Your using sum() and avg(), which means you know what you are doing with the functions. Like visakh16 said, the logic looks fine, what does SQL say is the problem?

I am a writer for the SQL Tutorial and Reference (http://www.afterhoursprogramming.com/tutorial/SQL/Overview/) section of afterhoursprogramming.com
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-01-07 : 10:02:23
the only issue might be this but cant tell much without knowing the datatypes of operands.

http://beyondrelational.com/modules/2/blogs/70/posts/10825/beware-of-implicit-conversions.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

ahmedpower
Starting Member

6 Posts

Posted - 2013-01-07 : 11:25:07
Can you write the syntax for me as i can test it , Please as I am not profession like that complecated Syntax

Ahmed Soliman
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-01-07 : 11:31:14
post some sample data and your expected output without which i'm not sure what you're after!

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -