Sql 中having 和where的区别 SQL hardest question What is the difference between the WHERE and HAVING claus
在一个含有group by where 和having的sql语句中,这三个语句执行的顺序:
1、先执行where找到符合条件的数据
2、执行group by子句将数据分组,group by子句中的select的返回字段中要么出现在group by后面的字段中,要么是聚合函数。
3、执行having对分组过滤不符合条件的组,having 后面的字段只能从 group by 返回的字段中选择。
原创
2016-09-22 16:57:37 ·
1007 阅读 ·
0 评论