rendered paste bodyselect store_num, sum(total_amt - sales_tax)/count(*)
from orders_p use index (PRIMARY)
where ord_date>='20070101' and ord_date<='20070128'
and (ord_type not like '%C%') and (total_amt - sales_tax >= 2.00)
group by store_num
This took over 17 minutes to run?!
+--------+-------------+--------+--------+---------------+--------+---------+--------+--------+--------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+--------+-------------+--------+--------+---------------+--------+---------+--------+--------+--------+
| 1 | SIMPLE | orders_p| index | [NULL] | PRIMARY| 21 | [NULL] | 6297645| Using where|
+--------+-------------+--------+--------+---------------+--------+---------+--------+--------+--------+
+----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| orders_p | 0 | PRIMARY | 1 | store_num | A | [NULL] | [NULL] | [NULL] | | BTREE | |
| orders_p | 0 | PRIMARY | 2 | ord_date | A | [NULL] | [NULL] | [NULL] | | BTREE | |
| orders_p | 0 | PRIMARY | 3 | ord_num | A | [NULL] | [NULL] | [NULL] | | BTREE | |
| orders_p | 0 | PRIMARY | 4 | ord_type | A | 6294251 | [NULL] | [NULL] | | BTREE | |
+----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+