mysql avg(currentPrice)怎么取两位小数
mysql avg(currentPrice)如何取两位小数。
mysql avg(currentPrice)如何取两位小数。
currentPrice 字段是varchar(8)。
------解决方案--------------------
round 一下应该就可以了。
mysql avg(currentPrice)如何取两位小数。
currentPrice 字段是varchar(8)。
------解决方案--------------------
round 一下应该就可以了。
- SQL code
mysql> select 1.234,round(1.234,2); +-------+----------------+ | 1.234 | round(1.234,2) | +-------+----------------+ | 1.234 | 1.23 | +-------+----------------+ 1 row in set (0.06 sec) mysql>
------解决方案--------------------
- SQL code
mysql> select currentPrice from t_lonelyriver; +--------------+ | currentPrice | +--------------+ | 1.23456 | | 1.26776 | | 1.26432 | +--------------+ 3 rows in set (0.00 sec) mysql> select avg(currentPrice),round(avg(currentPrice),2) -> from t_lonelyriver; +-------------------+----------------------------+ | avg(currentPrice) | round(avg(currentPrice),2) | +-------------------+----------------------------+ | 1.25554666666667 | 1.26 | +-------------------+----------------------------+ 1 row in set (0.05 sec) mysql>