Search code examples
sqlsql-serverisnull

SQL Select ISNULL not working


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.


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