i want to optimize this query,
select location_id, dept_id,
round(sum(sales),0), sum(qty),
count(distinct tran_id),
now()
from tra
For this query:
select location_id, dept_id,
round(sum(sales), 0), sum(qty), count(distinct tran_id),
now()
from tran_sales
where tran_date <= '2016-12-24'
group by location_id, dept_id;
There is not much you can do. One attempt would be a covering index: (tran_date, location_id, dept_id, sales, qty)
, but I don't think that will help much.