0

enter image description here

I used the query below to extract the data fro the table but it does not working.

     SELECT A.ID, AVG(ISNULL(score,0)) AS sc FROM A 
               LEFT OUTER JOIN B ON A.ID = B.ID 
            WHERE A.aClass = '1st'

I wanted it to return all the data from Table A with its corresponding average score and return 0 if there is no score yet. Can anyone help me figure out the problem.

2
  • Why do you have a duplicated ID in table b? Commented Feb 5, 2014 at 0:51
  • That is for example ID 1 has two records of score. Commented Feb 5, 2014 at 0:53

1 Answer 1

1

Try this

 SELECT A.ID, AVG(ISNULL(B.score,0)) AS sc 
 FROM A 
     LEFT OUTER JOIN B ON A.ID = B.ID 
 WHERE A.aClass = '1st'
 GROUP BY A.ID
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.