Page 1 of 1

Limit digits after decimal points in SQL

Posted: Wed Sep 27, 2017 9:22 pm
by mister_v
Hello,

I have a database with a lot of numbers,
I try to get the average, that works but I get up to 8 digits behind the decimal point (mostly 0).

Code: Select all

SELECT avg(number) FROM table;

Re: Limit digits after decimal points in SQL

Posted: Thu Sep 28, 2017 6:40 pm
by chris
I know 2 ways:
With round

Code: Select all

SELECT ROUND( AVG(number) , 2 ) FROM table;
Or with DECIMAL:

Code: Select all

SELECT ( AVG(number) AS DECIMAL(16, 2) )FROM table;
Both should work