Strange MySQL AVG() anomaly NULL values

前端 未结 5 984
小蘑菇
小蘑菇 2020-12-08 21:27

What I\'am doing :

create table sample (id INT(10) PRIMARY KEY AUTO_INCREMENT,name varchar(255),marks INT(10));

insert into sample (name,marks) VALUES(\'sam         


        
5条回答
  •  庸人自扰
    2020-12-08 21:54

    Try:

    select avg(case marks when null then 0 else marks end) from sample group by name;
    

    Or try and avoid nulls in the table ;)

提交回复
热议问题