通过MySQL语句中各个部分的执行顺序理解其写法
本文解释了MySQL在执行语句时的逻辑,帮助更好地理解怎样写出正确的SQL语句。
手写顺序:
SELECT DISTINCT
FROM
JOIN ON
WHERE
GROUP BY
HAVING
ORDER BY
LIMIT
MySQL执行顺序
FROM
ON
JOIN
WHERE
GROUP BY
HAVING
DISTINCT
ORDER BY
LIMIT
where 先执行
应该选D。此处对于SUM(area)的限制应该由having来完成,因为where是在group by之前进行筛选,不知道将哪些area拿来做筛选。
group by
最后应该为group by matchid, mdate