如何从mysql中的结果中删除十进制数字?

时间:2017-03-02 04:42:27

标签: mysql sql

我想删除十进制后的数字如何解决?

我的查询是:

SELECT city_name,
       Assignedto,
       COUNT(Assignedto) AS TC,
       CONCAT(count(CASE
                        WHEN STATUS = 'CLOSED' THEN 1
                        ELSE NULL
                    END) * 100 / count(1), '%') AS SC,
       CONCAT(count(CASE
                        WHEN STATUS = 'PENDING' THEN 1
                        ELSE NULL
                    END) * 100 / count(1), '%') AS PC,
       SUM(TIMESTAMPDIFF(MINUTE,Request_Date, Xetr))/60 AS WH,
       (154440-sum(TIMESTAMPDIFF(MINUTE,Request_Date, Xetr))/60) AS VH,
       CONCAT(COUNT(Feedback_Rate)/COUNT(Assignedto)*100,'%') AS Feed_Percent,
       SUM(Feedback_Rate)/(count(Feedback_Rate)*5)*5 AS AVG_Feedback
FROM `it_service_ticket`
INNER JOIN `it_problem`ON `it_service_ticket`.`it_problem_id`=`it_problem`.`it_problem_id`
INNER JOIN `city_master` ON `it_service_ticket`.cityid=`city_master`.city_id
WHERE `it_service_ticket`.`xetr` BETWEEN '2016-04-01 12:00:00 AM' AND '2017-02-28 12:00:00 PM'
GROUP BY Assignedto
ORDER BY city_name ASC;           

输出

+-------------------------+-------------------------+-------+------------+----------+------------+--------------+-----------+---------+
|       City_Name         |       AssigneeTo        |  TC   |    SC      |   PC     |    WH      |     VH       | Feedback  | Average |
+-------------------------+-------------------------+-------+------------+----------+------------+--------------+-----------+---------+
| Ahmedabad               | mahesh.patel@corp.in  |  297  | 100.0000%  | 0.0000%  |  147.0667  | 154292.9333  | 43.4343%  |  4.4031 |

|艾哈迈达巴德| mahesh.patel@corp.in | 297 | 100.0000%| 0.0000%| 147.0667 | 154292.9333 | 43.4343%| 4.4031 |

2 个答案:

答案 0 :(得分:2)

  1. 如果要舍入小数位,请使用ROUND(yourColumn,0)函数。

    因此13.78将成为14

  2. 如果你想摆脱小数位,用户FLOOR(yourColumn)

    因此13.78将成为13

  3. 所以例如

    SUM(TIMESTAMPDIFF(MINUTE,Request_Date, Xetr))/60 AS WH

    应改为

    ROUND(SUM(TIMESTAMPDIFF(MINUTE,Request_Date, Xetr))/60,0) AS WH

    编辑:这将照顾您的%

    CONCAT(
            ROUND(count(CASE
                WHEN STATUS = 'PENDING' THEN 1
                ELSE NULL
            END) * 100 / count(1),0)
            , '%') AS PC
    

    对删除小数位所需的所有列执行相同的操作。

答案 1 :(得分:2)

您应该在Mysql中使用TRUNCATE()作为示例

SELECT TRUNCATE(525.123,0) //525

SELECT TRUNCATE(525.123,1) //525.1

SELECT TRUNCATE(525.123,2) //525.12