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
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Average Scores
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

moorzeee
Starting Member

2 Posts

Posted - 07/15/2013 :  15:55:52  Show Profile  Reply with Quote
Hiya all

I have a requirement to return average appointment scores recorded as part of an appointment. I need to average the start appointment scores and the end appointment scores.
My table structure is as follows:
A Client has a Referral and a Referral has 0 or many Appointments. at each Appointment a Client receives a couple of AppointmentScores.

I am struggling to work out how I can return the average starting score and average ending score?

Can you help me out?

Cheers

James K
Flowing Fount of Yak Knowledge

3589 Posts

Posted - 07/15/2013 :  20:29:39  Show Profile  Reply with Quote
SELECT
   c.Client,
   AVG(r.startApptScore),
   AVG(r.endApptScore)
FROM
   Client c
   INNER JOIN Referral r on 
      r.ClientId = r.ClientId
GROUP BY
   ClientID
If you can post the DDL for the tables and some sample data, that would enable someone to post more precise answers. If you need guidance on retrieving DDLs, see here: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 07/16/2013 :  01:11:42  Show Profile  Reply with Quote

SELECT c.ClientName,
AVG(a.StartScore*1.0) AS AverageStartScore,
AVG(a.EndScore*1.0) AS AverageEndScore
FROM Client c
INNER JOIN Referal r
ON r.ClientID = c.ClientID
LEFT JOIN Appointment a
ON a.ReferalID = r.ReferalID
GROUP BY ClientName


assuming Appointments are in a different table as per your explanation

I've also assumed columnnames in table so make sure you replace them with correct ones
In case you table structures are completely different and you've difficulty mapping them please post DDL for use to help you with accurate solution

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
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.05 seconds. Powered By: Snitz Forums 2000