Does MySQL eliminate common subexpressions between SELECT and HAVING/GROUP BY clause
问题 I often see people answer MySQL questions with queries like this: SELECT DAY(date), other columns FROM table GROUP BY DAY(date); SELECT somecolumn, COUNT(*) FROM table HAVING COUNT(*) > 1; I always like to give the column an alias and refer to that in the GROUP BY or HAVING clause, e.g. SELECT DAY(date) AS day, other columns FROM table GROUP BY day; SELECT somecolumn, COUNT(*) AS c FROM table HAVING c > 1; Is MySQL smart enough to notice that the expressions in the later clauses are the same