Limit digits after decimal points in SQL

Post Reply
mister_v
Posts: 188
Joined: Thu Mar 04, 2010 9:19 pm

Limit digits after decimal points in SQL

Post 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;
chris
Site Admin
Posts: 194
Joined: Mon Jul 21, 2008 9:52 am

Re: Limit digits after decimal points in SQL

Post 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
Post Reply