A very simple query which work
select avg(price) from cars where type = 'electric';
the result is
1 --------------------------------- 45000,00000000000
I want to remove the ,00000000000 to obtain
1 --------------------------------- 45000
I have tried cast and round but without success. I’m on Db2
This nice ltrim works fine for all type of cars
select replace(ltrim(replace(price,'0',' ')),' ','0') from cars;
but using with avg return the string with the 00000
select replace(ltrim(replace(avg(price),'0',' ')),' ','0') from cars where type = 'electric';
the result is..
45000.00000000000
π Only the , is changed.
Advertisement
Answer
cast
ing this value should just work:
select cast(avg(price) as int) as avg_int from cars where type = 'electric';