In case you have your own slow SQL query, you can optimize it automatically here.
For the query above, the following recommendations will be helpful as part of the SQL tuning process.
You'll find 3 sections below:
SELECT
`total` AS `total`
FROM
`mytable` AS `A`,
(SELECT
MIN(`mytable`.`date`) AS `firstValue`,
MAX(`mytable`.`date`) AS `lastValue`
FROM
`mytable`
WHERE
`mytable`.`date` BETWEEN '2018-10-03 00:00:00' AND '2018-10-03 00:59:59'
AND `mytable`.`id_device` = 1) AS `B`
WHERE
`A`.`date` IN (
`B`.`firstValue`, `B`.`lastValue`
)
AND `id_device` = 1
ORDER BY
`A`.`date`