Skip to content
Advertisement

SQL – WHERE for 2nd SELECT object

I’m trying to find an average of 2 items in my SQL table, an average commission of people who receive a commission from the table, and an average commission, including those who do not get a commission (null).

My code:

This is what I get:

This is what I want:

This is what I want, the AVEALL is an average commission of everyone, including those with a null value.

Thanks.

Advertisement

Answer

You can use COALESCE to convert NULL values to 0 and then take the average to get your AVEALL value:

Demo on dbfiddle

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement