# Optimizing a query

**URL:** <https://forums.percona.com/t/optimizing-a-query/1592>\
**Category:** Other MySQL® Questions\
**Created:** [January 18, 2011, 2:31pm UTC](https://forums.percona.com/t/optimizing-a-query/1592 "2011-01-18T14:31:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gjuan](https://avatars.discourse-cdn.com/v4/letter/g/53a042/32.png) [@gjuan](https://forums.percona.com/u/gjuan)\
**Post date:** [January 18, 2011, 2:31pm UTC](https://forums.percona.com/t/optimizing-a-query/1592/1 "2011-01-18T14:31:33Z")

</div>

Hi,

Any idea to optimize the next query:

SELECT  
COUNT(_) - SUM(success) AS failed,  
COUNT(_) AS total,  
SUM(success) / COUNT(\*) \* 100 AS percent,  
FROM\_UNIXTIME(FLOOR(UNIX\_TIMESTAMP(TIME) / 300) \* 300) AS START  
FROM reports  
GROUP BY FLOOR(UNIX\_TIMESTAMP(TIME) / 300) LIMIT 100;

Thanks for the help.

---

<div class="post-metadata">

**Author:** ![xaprb](https://avatars.discourse-cdn.com/v4/letter/x/49beb7/32.png) [@xaprb](https://forums.percona.com/u/xaprb)\
**Post date:** [February 15, 2011, 6:15am UTC](https://forums.percona.com/t/optimizing-a-query/1592/2 "2011-02-15T06:15:46Z")

</div>

You need to index it and rewrite it so that an index can be used for the GROUP BY. You should include SHOW CREATE TABLE reports\G
