MySQL group-by very slow

后端 未结 5 2150
予麋鹿
予麋鹿 2021-02-07 05:34

I have the folowwing SQL query

SELECT CustomerID FROM sales WHERE `Date` <= \'2012-01-01\' GROUP BY CustomerID

The query is executed over 11

5条回答
  •  一个人的身影
    2021-02-07 06:16

    Wouldn't this one be a lot faster and achieve the same?

    SELECT DISTINCT CustomerID FROM sales WHERE `Date` <= '2012-01-01'
    

    Make sure to place an index on Date, of course. I'm not entirely sure but indexing CustomerID might also help.

提交回复
热议问题