Why does this SELECT statment return a float value? How can I cast it into an integer?
select area.name, coalesce(((avg(recording.length)*count(recording.length))/1000/60),0)
Why does this SELECT statment return a float value? How can I cast it into an integer?
select area.name, coalesce(((avg(recording.length)*count(recording.length))/1000/60),0)
If the result of avg(recording.length)*count(recording.length)
isn't a multiple of 60000
, you'll get a fraction when you do that division. You can use ROUND()
to round this to the nearest integer.
Also, since the average is the sum divided by the count, multiplying by the count just returns the sum. You can just use that directly.
SELECT area.name, coalesce(ROUND(SUM(recording.length)/1000/60)), 0)