sql – “HAVING … GROUP BY”和“GROUP BY … HAVING”之间的区别

前端之家收集整理的这篇文章主要介绍了sql – “HAVING … GROUP BY”和“GROUP BY … HAVING”之间的区别前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有两个列的表MYTABLE:A和B.

我有以下几段代码

SELECT MYTABLE.A FROM MYTABLE 
    HAVING SUM(MYTABLE.B) > 100
    GROUP BY MYTABLE.A

SELECT MYTABLE.A FROM MYTABLE 
    GROUP BY MYTABLE.A
    HAVING SUM(MYTABLE.B) > 100

它是一样的吗?这两个代码是否有可能返回不同的结果集?

先感谢您

解决方法

据记载,没有区别.人们习惯于在GROUP BY之后看到HAVING.

http://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_10002.htm#SQLRF20040

Specify GROUP BY and HAVING after the where_clause and hierarchical_query_clause. If you specify both GROUP BY and HAVING,then they can appear in either order.

http://sqlfiddle.com/#!4/66e33/1

原文链接:https://www.f2er.com/mssql/75053.html

猜你在找的MsSQL相关文章