SQL:HAVING子句 [英] SQL: HAVING clause

查看:107
本文介绍了SQL:HAVING子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请参见以下SQL语句:

See the following SQL statement:

SELECT datediff("d", MAX(invoice.date), Now) As Date_Diff
      , MAX(invoice.date) AS max_invoice_date
      , customer.number AS customer_number
FROM invoice 
    INNER JOIN customer 
        ON invoice.customer_number = customer.number
GROUP BY customer.number 

如果添加了以下内容:

HAVING datediff("d", MAX(invoice.date), Now) > 365

这会简单地排除Date_Diff< = 365的行吗?

would this simply exclude rows with Date_Diff <= 365?

这里的HAVING子句应该有什么作用?

What should be the effect of the HAVING clause here?

我没有遇到这里所说的答案. mdb的副本位于 http://hotfile.com/dl/40641614 /2353dfc/test.mdb.html (无宏或病毒). VISDATA.EXE用于执行查询.

I am not experiencing what the answers here are saying. A copy of the mdb is at http://hotfile.com/dl/40641614/2353dfc/test.mdb.html (no macros or viruses). VISDATA.EXE is being used to execute the queries.

我认为问题可能出在VISDATA,因为我通过DAO遇到了不同的结果.

I think the problem might be VISDATA, because I am experiencing different results via DAO.

推荐答案

正如已经指出的,是的,这就是效果.为了完整起见,"HAVING"类似于"WHERE",但是对于已经聚合(分组)的值(例如,在这种情况下为MAX或SUM或COUNT,或任何其他聚合函数).

As already pointed out, yes, that is the effect. For completeness, 'HAVING' is like 'WHERE', but for the already aggregated (grouped) values (such as, MAX in this case, or SUM, or COUNT, or any of the other aggregate functions).

这篇关于SQL:HAVING子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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