mysql avg(currentPrice)如何取两位小数。

lonelyriver 2009-06-05 12:27:25
mysql avg(currentPrice)如何取两位小数。
currentPrice 字段是varchar(8)。
...全文
4796 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
那时很爱倪 2012-08-17
  • 打赏
  • 举报
回复
谢谢!正好用到
ACMAIN_CHM 2009-06-05
  • 打赏
  • 举报
回复

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>


ACMAIN_CHM 2009-06-05
  • 打赏
  • 举报
回复

round 一下应该就可以了。

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>


56,678

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧