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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Average Scores
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

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?


James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 07/15/2013 :  20:29:39  Show Profile  Reply with Quote
   Client c
   INNER JOIN Referral r on 
      r.ClientId = r.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:
Go to Top of Page

Very Important crosS Applying yaK Herder

52326 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
Go to Top of Page
  Previous Topic Topic Next 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.02 seconds. Powered By: Snitz Forums 2000