Skip to content
Advertisement

Divide by zero error encountered when using group by

I’ve got the below piece of code in my query:

Both fields are of DateTime datatype. The problem is that when I include group by the above piece of code throws this error:

Divide by zero error encountered.

Warning: Null value is eliminated by an aggregate or other SET operation.

I’ve read some threads here and tried using this:

However, it didn’t help, I still get the same issue as before.

Advertisement

Answer

The NULLIF() goes outside the COUNT():

That is, you need to check the result of the COUNT(), not the column being counted.

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