MYSQL Count(Distinct) Group By

init3

This select keeps timing out:

SELECT COUNT(DISTINCT `invoices`) 
FROM `data` 
WHERE date BETWEEN '2013-07-01' AND '2014-06-30' 
GROUP BY `store`

I have made indexes on invoices, date, store and invoices, store, date. Any help is appreciated.

Marcx

try

SELECT `store`, COUNT(*) FROM 
   (SELECT `store`, `invoices`
          FROM `data` 
         WHERE date BETWEEN '2013-07-01' AND '2014-06-30' 
       GROUP BY `store`, `invoices`
   ) tbl
GROUP BY `store`

Here's a fiddle, without the date column and check...

http://sqlfiddle.com/#!9/fb83c/5/0

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related