100 -6ren">
gpt4 book ai didi

sql - "HAVING ... GROUP BY"和 "GROUP BY ... HAVING"之间的区别

转载 作者:行者123 更新时间:2023-12-02 09:51:14 29 4
gpt4 key购买 nike

我的表 MYTABLE 有 2 列:AB

我有以下代码片段:

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

关于sql - "HAVING ... GROUP BY"和 "GROUP BY ... HAVING"之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20471319/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com