聚合函数无法在 mysql 中工作
aggregate function can`t work in mysql
我想在 mysql 上使用聚合函数。我必须使用这个查询。
SELECT COUNT (*) FROM \`pelayanan\` where \`ID_STATUS\` = '1'
但是,它不起作用。它变成了错误。
1064 - You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near '*) FROM `pelayanan` where `ID_STATUS` = '1' LIMIT 0, 25' at
line 1
其他聚合函数如 sum 也有同样的错误。
我该如何解决这个问题?
这是您的查询:
SELECT COUNT (*)
FROM pelayanan
where ID_STATUS = '1';
space 不允许出现在任何函数之后,包括 count()
。所以:
SELECT COUNT(*)
FROM pelayanan
WHERE ID_STATUS = '1';
这在 documentation:
的注释中有解释
Note
By default, there must be no whitespace between a function name and
the parenthesis following it. This helps the MySQL parser distinguish
between function calls and references to tables or columns that happen
to have the same name as a function. However, spaces around function
arguments are permitted.
我想在 mysql 上使用聚合函数。我必须使用这个查询。
SELECT COUNT (*) FROM \`pelayanan\` where \`ID_STATUS\` = '1'
但是,它不起作用。它变成了错误。
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*) FROM `pelayanan` where `ID_STATUS` = '1' LIMIT 0, 25' at line 1
其他聚合函数如 sum 也有同样的错误。
我该如何解决这个问题?
这是您的查询:
SELECT COUNT (*)
FROM pelayanan
where ID_STATUS = '1';
space 不允许出现在任何函数之后,包括 count()
。所以:
SELECT COUNT(*)
FROM pelayanan
WHERE ID_STATUS = '1';
这在 documentation:
的注释中有解释Note
By default, there must be no whitespace between a function name and the parenthesis following it. This helps the MySQL parser distinguish between function calls and references to tables or columns that happen to have the same name as a function. However, spaces around function arguments are permitted.