单个查询中的MySQL百分比

时间:2013-02-23 15:38:48

标签: mysql

到目前为止,我已经得到了这个:\

SELECT Bike_Number, MaintFaultDetails, MaintactionTaken, MaintfaultDate, MaintActionDate,
       COUNT(*) 
FROM   MaintHistory
WHERE  (MaintfaultDate + 5) < MaintactionTaken 

SELECT Bike_Number, MaintFaultDetails, MaintactionTaken, MaintfaultDate, MaintActionDate,
       COUNT(*) 
FROM   MaintHistory

我会添加/编辑什么,以便计算超过5天的自行车百分比

1 个答案:

答案 0 :(得分:0)

试试

 SELECT Bike_Number, MaintFaultDetails, MaintactionTaken, MaintfaultDate, MaintActionDate,
   Concat(count(Bike_Number)*100/COUNT(*).'%' ) as percent
 FROM   MaintHistory
 WHERE  DATE_ADD(MaintfaultDate, INTERVAL +5 DAY) < MaintactionTaken