单个查询中的MySQL百分比

时间:2022-09-25 16:47:53

So far I've got this:\

到目前为止我有这个:

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

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

What would I add/edit so that it calculates the percentags of bikes that took longer than 5 days

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

1 个解决方案

#1


0  

try that

 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 

#1


0  

try that

 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