MySQL返回2位小数

时间:2014-10-02 14:43:55

标签: mysql

我有一个复杂的查询返回一个百分比,但我需要让它只返回2位小数。我已经搜索了论坛和trues截断,圆形,强制转换,小数和其他一些我确定我失踪了。我完全不知道从哪里开始。查询如下。任何帮助将不胜感激。

代码

SELECT branch, SUM( monthly_total / ( 
   SELECT SUM(hour1) 
   FROM `door_count` 
   WHERE `numeric_month` <= MONTH( CURRENT_DATE( ) ) 
   AND fy = 2013
   AND numeric_month <> '0'
   AND branch = 'Main St.'
  ) *100 
) 
FROM door_count
WHERE fy = 2014
AND branch = 'Main St.';

1 个答案:

答案 0 :(得分:0)

使用ROUND()函数:

SELECT branch, ROUND(SUM( monthly_total / ( 
   SELECT SUM(hour1) 
   FROM `door_count` 
   WHERE `numeric_month` <= MONTH( CURRENT_DATE( ) ) 
   AND fy = 2013
   AND numeric_month <> '0'
   AND branch = 'Main St.'
  ) *100 
), 2) 
FROM door_count
WHERE fy = 2014
AND branch = 'Main St.';