I want to use aggregate function on mysql. I have to use this query.
SELECT COUNT (*) FROM \`pelayanan\` where \`ID_STATUS\` = '1'
But, It doesn`t work. It became error.
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
It same error for the other aggregate function like sum.
How can I solve this problem?
This is your query:
SELECT COUNT (*)
FROM pelayanan
where ID_STATUS = '1';
It is easier to see the problem when formatted correctly (for Stack Overflow). A space is not allowed after any function, including count()
. So:
SELECT COUNT(*)
FROM pelayanan
WHERE ID_STATUS = '1';
This is explained in a note in the 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.