mySQL count only returning one result unless using group by

前端 未结 2 1561
我寻月下人不归
我寻月下人不归 2021-01-23 10:30

using the SQL query

select u.name,count(u.name) as \'followers\'
from user u,follow f
where u.type = \'c\' AND f.followee = u.email
group by u.name
2条回答
  •  不知归路
    2021-01-23 10:38

    When you use count without group by it will count all the records and returns single line while when you use count with group by it will group the users on the base of their names and returns the count of each group.

提交回复
热议问题