简体   繁体   English

SQL Select ISNULL不起作用

[英]SQL Select ISNULL not working

在此处输入图片说明

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. 我希望它返回表A的所有数据及其相应的平均分数,如果还没有分数,则返回0。 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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM