i am usinga MySql database and i am trying to get the total duration (which is in milliseconds format in the database) from the "builds" table, i need it in this format (hh:mm:ss).
this is my query :
SELECT
SUM(Builds.Duration) as duration , DATE_FORMAT(Builds.date, "%Y-%c-%d") as date
FROM Builds
JOIN Labels ON Builds.Labels_label_id = Labels.label_id
JOIN CITools ON CITools.tool_id = Labels.CITools_tool_id
WHERE Labels.label_name LIKE '%SPOT%' AND CITools.tool_name='jenkins' AND Builds.date >=
'2022-03-01' AND Builds.date <= '2022-04-01'
GROUP BY MONTH(Builds.date)
And this is the result:
| duration | date |
__________________________
| 5634635345 | 2022-03-01 |
| 5491338343 | 2022-04-01 |
| . | . |
| . | . |
The following recommendations will help you in your SQL tuning process.
You'll find 3 sections below:
ALTER TABLE `Builds` ADD INDEX `builds_idx_date` (`date`);
ALTER TABLE `Builds` ADD INDEX `builds_idx_month_date` (`month_date`);
ALTER TABLE `CITools` ADD INDEX `citools_idx_tool_name_tool_id` (`tool_name`,`tool_id`);
ALTER TABLE `Labels` ADD INDEX `labels_idx_label_id` (`label_id`);
SELECT
SUM(Builds.Duration) AS duration,
DATE_FORMAT(Builds.date,
"%Y-%c-%d") AS date
FROM
Builds
JOIN
Labels
ON Builds.Labels_label_id = Labels.label_id
JOIN
CITools
ON CITools.tool_id = Labels.CITools_tool_id
WHERE
Labels.label_name LIKE '%SPOT%'
AND CITools.tool_name = 'jenkins'
AND Builds.date >= '2022-03-01'
AND Builds.date <= '2022-04-01'
GROUP BY
Builds.month_date
ORDER BY
NULL