Defain
Defain

Reputation: 1325

How to round this in SQL

we just started our studying on SQL and I seem to have a slight problem with one exercise.

I would need to round the result of

SELECT AVG(points) AS Average FROM table;

I was trying to do it with subquery but I just did not hit the correct one even tough similar subqueries with only select seem to work well.

Any help?

Upvotes: 1

Views: 146

Answers (4)

Darren
Darren

Reputation: 70728

Use ROUND

SELECT ROUND(AVG(POINTS), 2) AS Average
FROM table;

Upvotes: 3

Praveen Nambiar
Praveen Nambiar

Reputation: 4892

Use the ROUND() function.

SELECT ROUND(AVG(POINTS), 1) AS Average FROM table;

Upvotes: 0

VenVig
VenVig

Reputation: 905

Select Round(Avg(Points),2) as Average from table

Reference: http://msdn.microsoft.com/en-us/library/ms175003.aspx Does this help ?

Upvotes: 0

echo_Me
echo_Me

Reputation: 37233

try this

   SELECT ROUND(AVG(POINTS), 3) AS Average FROM your_table;

                             ^^--if you want round by two decimals then use 2 and so on

Upvotes: 0

Related Questions