Reputation: 17
I want to count the number of ABC group using id.
SELECT group, count(id) as total FROM `user` WHERE group=`ABC`;
What's wrong? Many thanks.
Upvotes: 0
Views: 57
Reputation: 379
If you want to get COUNT of users, who has the "group" field = "ABC"
SELECT count(id) as total FROM user WHERE group='ABC';
Also, it's better to avoid using SQL keywords in column names (GROUP is an SQL keyword)
Upvotes: 0
Reputation: 3592
Try this:
SELECT group, count(id) as total FROM `user`
group by group having group like 'ABC';
Upvotes: 0
Reputation: 5031
Include the columns in the select list in group by
clause when using aggregate functions.
SELECT group, count(id) as total FROM user
WHERE group=`ABC`
GROUP BY group
Else simply get the count with out using other columns in the select statement.
SELECT count(id) as total FROM user
WHERE group=`ABC`
Upvotes: 1