Hi!
I have to tables with 50.000 rows (lets say 'sales' and 'detail')
The table 'detail' has some rows: 'store', 'departament', 'sub_dep', 'sale_id' that conform a key. The same rows are in the table 'sales'.
Now I have to count all the values in table 'details' where certain restrictions. And for each month of the year display the total count.
here is my query for only one month:
This query is veeerrrryy slow! ... I can't imagine doing a query for each month in my PHP.
What can I do?... is there a better query?
Thanks In advance!
I have to tables with 50.000 rows (lets say 'sales' and 'detail')
The table 'detail' has some rows: 'store', 'departament', 'sub_dep', 'sale_id' that conform a key. The same rows are in the table 'sales'.
Now I have to count all the values in table 'details' where certain restrictions. And for each month of the year display the total count.
here is my query for only one month:
Code:
SELECT * FROM sales a, detail b WHERE
(a.store = b.store)
AND (a.departament = b.departament)
AND (a.sub_dep = b.sub_dep)
AND (a.sale_id = b.sale_id)
AND (a.vendor= 'jmss')
AND (YEAR( b.date) = '2003')
AND (MONTH( b.date) = '01')
This query is veeerrrryy slow! ... I can't imagine doing a query for each month in my PHP.
What can I do?... is there a better query?
Thanks In advance!