Cbdy
2021-06-13 19:25:34 +08:00
HAVING and WHERE are often confused by beginners, but they serve different purposes. WHERE is taken into account at an earlier stage of a query execution, filtering the rows read from the tables. If a query contains GROUP BY, data from the tables are grouped and aggregated. After the aggregating operation, HAVING is applied, filtering out the rows that don't match the specified conditions. Therefore, WHERE applies to data read from tables, and HAVING should only apply to aggregated data, which are not known in the initial stage of a query.
To view the present condition formed by the GROUP BY clause, the HAVING clause is used.
---
当然,如果你一定都要“复用”WHERE 这个关键词也可以(万物皆虚,万物皆允,你可以设计一个基于“喵喵喵”关键词的的结构化查询语言),通过上下文来决定的“WHERE”的含义,这个是设计的问题,而我不认为这是一个好的设计