I have the following query where it takes minutes to load, when actually I need only to count how many rows it returns. I would like to know if is it possible to improve this query?
SELECT (clock - clock mod 300) as time, avg(value) as value FROM table.history_uint WHERE itemid = 82660 AND clock >= UNIX_TIMESTAMP('".$date."') AND clock <= UNIX_TIMESTAMP('".$date."') GROUP BY time;
This is my code:
$queryPageInfo = "SELECT (clock - clock mod 300) as time, avg(value) as value FROM table.history_uint WHERE itemid = 82660 AND clock >= UNIX_TIMESTAMP('".$date."') AND clock <= UNIX_TIMESTAMP('".$date."') GROUP BY time";
$resultPageInfo = $mysqli->query($queryPageInfo);
$qtd = $resultPageInfo->num_rows;