Mysql AVG to ignore zero

后端 未结 4 684
梦毁少年i
梦毁少年i 2021-01-31 19:20

I need to perform an avg on a column, but I know that most of the values in that column will be zero. Out of all possible rows, only two will probably have positive values. How

4条回答
  •  遇见更好的自我
    2021-01-31 20:01

    You can convert zeros to NULL, then AVG() function will work only with not NULL values.

    UPDATE table SET column = NULL WHERE column='0';
    SELECT AVG(column) FROM table;
    

提交回复
热议问题