Can anyone say why this select returns 3.0 instead of 3.5:
SELECT coalesce(1.0*(7/2),0) as foo
This one returns 3:
SELECT coalesce(7/2,0) as foo
I'm just trying to divide a SUM by COUNT to find an average. I need it 0 if null and 1 rounded by 1 decimal in case I have results.
You need to do something like:
SELECT COALESCE((1.0 * 7)/2, 0) AS foo;
Well, 7/2 is an integer, 1.0 is numeric, and so 1.0*(7/2)==1.0 * 3 == 3.0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With