gpt4 book ai didi

java - 与mysql中的整数值进行比较

转载 作者:太空宇宙 更新时间:2023-11-03 10:58:43 25 4
gpt4 key购买 nike

我想编写一个 sql 查询,如果特定列的总和为零,则将检索结果。我试过如下:(我只写了检查部分,因为错误仅针对这部分)。

query=.... WHERE SUM(column1)='0'

coumn1 具有整数数据类型。我收到以下错误:

java.sql.SQLException: Invalid use of group function
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:946)

非常感谢任何帮助。谢谢。

最佳答案

您的查询是错误的。如果您想使用像 sum() 这样的聚合函数,您应该使用 having 子句。

The HAVING clause was added to SQL because the WHERE keyword could not be used with aggregate functions.

查看MySql documentation of SELECT :

The WHERE clause, if given, indicates the condition or conditions that rows must satisfy to be selected. where_condition is an expression that evaluates to true for each row to be selected. The statement selects all rows if there is no WHERE clause.

In the WHERE expression, you can use any of the functions and operators that MySQL supports, except for aggregate (summary) functions.

关于java - 与mysql中的整数值进行比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17906104/

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