Swag
Swag

Reputation: 2140

SQL AVG (average) returns lots of digits

When I do something like this:

SELECT AVG(Price) FROM Product WHERE ProductName = 'Shoe';

the SQL returns something like this: 6,5934348324242

An average number with a lot of digits.

Is it possible to do something in the query so the query returns 2/3 digits (for example: 6,59) instead of 10+ digits?

I am using MySql

Upvotes: 1

Views: 2339

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1270431

You can convert it to a decimal:

SELECT cast(AVG(Price) as decimal(6, 2))
FROM Product
WHERE ProductName = 'Shoe';

Upvotes: 5

Related Questions