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
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Average Scores

Author  Topic 

moorzeee
Starting Member

2 Posts

Posted - 2013-07-15 : 15:55:52
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
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-07-15 : 20:29:39
[code]SELECT
c.Client,
AVG(r.startApptScore),
AVG(r.endApptScore)
FROM
Client c
INNER JOIN Referral r on
r.ClientId = r.ClientId
GROUP BY
ClientID[/code]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

52326 Posts

Posted - 2013-07-16 : 01:11:42
[code]
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
[/code]

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
   

- Advertisement -