Mysql make AVG return null if any value is null

I'm trying to take an AVG from one of my columns in MySQL. However, the calculation must be done in another way if some of the values are null. So, I'm trying to make this:

SELECT AVG(amount) from sales returns me NULL if any row in the sales table has amount NULL. Can this be done?


I would try with (it counts nulls as zeros):

SELECT AVG(IFNULL(amount,0)) from sales

Edited (misinterpreted the question before):

SELECT IF(sum(amount is NULL), NULL, AVG(amount)) from sales

Need Your Help

Parallel.For statement return “System.InvalidOperationException” with a Bitmap Processing

c# multithreading parallel-processing system.drawing

Well, I have a code to apply a Rain Bow filter in "x" image, I have to do in two ways: Sequential & parallel, my sequential code is working without problems, but the parallel section doesn't wo...

Displaying Results of innerjoin by choice of quantity

php mysql row inner-join

I'm trying to innerjoin 2 tables. Table 1 contains ID of user online only. Tables 2 contains ID's of all users and their names.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.