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.
Author |
Topic |
moorzeee
Starting Member
2 Posts |
Posted - 2013-07-15 : 15:55:52
|
Hiya allI 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.ClientIdGROUP 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 |
|
|
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 AverageEndScoreFROM Client cINNER JOIN Referal rON r.ClientID = c.ClientIDLEFT JOIN Appointment aON a.ReferalID = r.ReferalIDGROUP BY ClientName[/code]assuming Appointments are in a different table as per your explanationI've also assumed columnnames in table so make sure you replace them with correct onesIn 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 MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|