Question

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.

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top