是否有子句“无用”在选择语句中?
我正在阅读一篇名为查询优化技术 - 写作技巧 高效,更快的SQL查询。
该文档表明在选择语句中,hastar子句是“无用的”:
提示#2:避免在Select语句中包含一个子句
所有行是在所有行之后用于过滤行的 选择,它像过滤器一样使用。 在选择中是没有用的 语句。它可以通过浏览最终结果表 查询解析不符合条件的行。
示例:
原始查询:
选择s.cust_id,count(s.cust_id) 来自Sh.sales s s.cust_id组 具有s.cust_id!='1660'和s.cust_id!='2';
改进的查询:
选择s.cust_id,count(cust_id) 来自Sh.sales s 其中s.cust_id!='1660' 和s.cust_id!='2' s.cust_id组;
问题:
该断言正确吗?在某些语句中,HASTER子句没有目的吗?
I’m reading a paper called Query Optimization Techniques - Tips For Writing
Efficient And Faster SQL Queries.
That document suggests that the HAVING clause is “useless” in a SELECT statement:
Tip #2: Avoid including a HAVING clause in SELECT statements
The HAVING clause is used to filter the rows after all the rows are
selected and it is used like a filter. It is quite useless in a SELECT
statement. It works by going through the final result table of the
query parsing out the rows that don’t meet the HAVING condition.Example:
Original query:
SELECT s.cust_id,count(s.cust_id) FROM SH.sales s GROUP BY s.cust_id HAVING s.cust_id != '1660' AND s.cust_id != '2';
Improved query:
SELECT s.cust_id,count(cust_id) FROM SH.sales s WHERE s.cust_id != '1660' AND s.cust_id !='2' GROUP BY s.cust_id;
Question:
Is that assertion correct? Does the HAVING clause not have a purpose in a SELECT statement?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果它没有用,那将不存在。
根据示例为true的那些群体,您将其用作
其目的是什么?您不能使用以及汇总功能的,例如,这是无效的:
If it were useless, it wouldn't exist.
Based on your example, you'd use it as e.g.
What is its purpose? You can't use
WHERE
along with aggregate functions, e.g. this is invalid: