{ "data": { "question": { "questionId": "1877", "questionFrontendId": "1729", "categoryTitle": "Database", "boundTopicId": 564380, "title": "Find Followers Count", "titleSlug": "find-followers-count", "content": "

Table: Followers

\n\n
\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| user_id     | int  |\n| follower_id | int  |\n+-------------+------+\n(user_id, follower_id) is the primary key for this table.\nThis table contains the IDs of a user and a follower in a social media app where the follower follows the user.
\n\n

 

\n\n

Write an SQL query that will, for each user, return the number of followers.

\n\n

Return the result table ordered by user_id.

\n\n

The query result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nFollowers table:\n+---------+-------------+\n| user_id | follower_id |\n+---------+-------------+\n| 0       | 1           |\n| 1       | 0           |\n| 2       | 0           |\n| 2       | 1           |\n+---------+-------------+\nOutput: \n+---------+----------------+\n| user_id | followers_count|\n+---------+----------------+\n| 0       | 1              |\n| 1       | 1              |\n| 2       | 2              |\n+---------+----------------+\nExplanation: \nThe followers of 0 are {1}\nThe followers of 1 are {0}\nThe followers of 2 are {0,1}\n
\n", "translatedTitle": "求关注者的数量", "translatedContent": "

表: Followers

\n\n
\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| user_id     | int  |\n| follower_id | int  |\n+-------------+------+\n(user_id, follower_id) 是这个表的主键。\n该表包含一个关注关系中关注者和用户的编号,其中关注者关注用户。
\n\n

 

\n\n

写出 SQL 语句,对于每一个用户,返回该用户的关注者数量。

\n\n

按 user_id 的顺序返回结果表。

\n\n

查询结果的格式如下示例所示。

\n\n

 

\n\n

示例 1:

\n\n
\n输入:\nFollowers 表:\n+---------+-------------+\n| user_id | follower_id |\n+---------+-------------+\n| 0       | 1           |\n| 1       | 0           |\n| 2       | 0           |\n| 2       | 1           |\n+---------+-------------+\n输出:\n+---------+----------------+\n| user_id | followers_count|\n+---------+----------------+\n| 0       | 1              |\n| 1       | 1              |\n| 2       | 2              |\n+---------+----------------+\n解释:\n0 的关注者有 {1}\n1 的关注者有 {0}\n2 的关注者有 {0,1}
\n", "isPaidOnly": false, "difficulty": "Easy", "likes": 11, "dislikes": 0, "isLiked": null, "similarQuestions": "[]", "contributors": [], "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"ruby\": false, \"bash\": false, \"swift\": false, \"golang\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"kotlin\": false, \"rust\": false, \"php\": false, \"typescript\": false, \"racket\": false, \"erlang\": false, \"elixir\": false}", "topicTags": [ { "name": "Database", "slug": "database", "translatedName": "数据库", "__typename": "TopicTagNode" } ], "companyTagStats": null, "codeSnippets": [ { "lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode" }, { "lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode" }, { "lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode" } ], "stats": "{\"totalAccepted\": \"5.4K\", \"totalSubmission\": \"8.6K\", \"totalAcceptedRaw\": 5414, \"totalSubmissionRaw\": 8588, \"acRate\": \"63.0%\"}", "hints": [], "solution": null, "status": null, "sampleTestCase": "{\"headers\":{\"Followers\":[\"user_id\",\"follower_id\"]},\"rows\":{\"Followers\":[[\"0\",\"1\"],[\"1\",\"0\"],[\"2\",\"0\"],[\"2\",\"1\"]]}}", "metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Followers(user_id int, follower_id int)\"\n ],\n \"mssql\": [\n \"Create table Followers(user_id int, follower_id int)\"\n ],\n \"oraclesql\": [\n \"Create table Followers(user_id int, follower_id int)\"\n ],\n \"database\": true\n}", "judgerAvailable": true, "judgeType": "large", "mysqlSchemas": [ "Create table If Not Exists Followers(user_id int, follower_id int)", "Truncate table Followers", "insert into Followers (user_id, follower_id) values ('0', '1')", "insert into Followers (user_id, follower_id) values ('1', '0')", "insert into Followers (user_id, follower_id) values ('2', '0')", "insert into Followers (user_id, follower_id) values ('2', '1')" ], "enableRunCode": true, "envInfo": "{\"mysql\":[\"MySQL\",\"

\\u7248\\u672c\\uff1aMySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"

mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"

Oracle Sql 11.2.<\\/p>\"]}", "book": null, "isSubscribed": false, "isDailyQuestion": false, "dailyRecordStatus": null, "editorType": "CKEDITOR", "ugcQuestionId": null, "style": "LEETCODE", "exampleTestcases": "{\"headers\":{\"Followers\":[\"user_id\",\"follower_id\"]},\"rows\":{\"Followers\":[[\"0\",\"1\"],[\"1\",\"0\"],[\"2\",\"0\"],[\"2\",\"1\"]]}}", "__typename": "QuestionNode" } } }