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.

有帮助吗?

解决方案

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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top