在别名HAVING和不使用HAVING之间有性能差异 [英] Is there a performance difference between HAVING on alias, vs not using HAVING

查看:467
本文介绍了在别名HAVING和不使用HAVING之间有性能差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好,我在学习, ,关于<$现在,我的问题是,如果这两个查询有不同的性能特点:








b

没有HAVING

  SELECT x + y AS z,t。 * FROM t 
WHERE
x = 1 and
x + y = 2

包含HAVING

  SELECT x + y AS z,t。* FROM t 
WHERE
x = 1
HAVING
z = 2


解决方案

HAVING用于包含GROUP BY的查询,或返回包含聚合函数结果的单个行。例如 SELECT SUM(score)FROM t HAVING SUM(scores)> 100

$



第二个查询被SQL标准视为无效,并且不被某些数据库系统。


Ok, I'm learning, bit by bit, about what HAVING means.

Now, my question is if these two queries have difference performance characteristics:

Without HAVING

SELECT x + y AS z, t.*  FROM t
WHERE 
x = 1 and
x+y = 2

With HAVING

SELECT x + y AS z, t.*  FROM t
WHERE 
x = 1
HAVING
z = 2

解决方案

HAVING is used for queries that contain GROUP BY or return a single row containg the result of aggregate functions. For example SELECT SUM(scores) FROM t HAVING SUM(scores) > 100 returns either one row, or no row at all.

The second query is considered invalid by the SQL Standard and is not accepted by some database systems.

这篇关于在别名HAVING和不使用HAVING之间有性能差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆