简体   繁体   English

SQL AVG(平均值)返回很多数字

[英]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 SQL返回如下内容: 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? 是否可以在查询中执行某些操作,以便查询返回2/3位(例如:6,59)而不是10+位?

I am using MySql 我正在使用MySql

You can convert it to a decimal: 您可以将其转换为小数:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM