读书人

mysql avg(currentPrice)怎么取两位小

发布时间: 2012-09-15 19:09:28 作者: rapoo

mysql avg(currentPrice)如何取两位小数。
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> 

读书人网 >Mysql

热点推荐