SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Get Total and Averge Query
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ahmedpower
Starting Member

Qatar
6 Posts

Posted - 01/06/2013 :  07:55:15  Show Profile  Reply with Quote
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

India
52325 Posts

Posted - 01/06/2013 :  10:13:16  Show Profile  Reply with Quote
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 - 01/07/2013 :  02:42:21  Show Profile  Reply with Quote
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

India
52325 Posts

Posted - 01/07/2013 :  10:02:23  Show Profile  Reply with Quote
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

Qatar
6 Posts

Posted - 01/07/2013 :  11:25:07  Show Profile  Reply with Quote
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

India
52325 Posts

Posted - 01/07/2013 :  11:31:14  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000