Meta's growth team wants to see how active each user is at sending friend requests. Write a query to find, for every user who has sent at least one friend request, their name and the total number of friend requests they've sent (regardless of whether the request was accepted, pending, or declined). Sort the results by total requests sent descending, then by name alphabetically for ties. ### Table Schema | Table | Column | Type | |---|---|---| | `users` | `user_id` | integer | | `users` | `name` | string | | `friend_requests` | `request_id` | integer | | `friend_requests` | `sender_id` | integer | | `friend_requests` | `status` | string | | `friend_requests` | `request_date` | date | ### Example Input: `users` | user_id | name | |---|---| | 1 | Alice | | 2 | Bob | | 3 | Carol | ### Example Input: `friend_requests` | request_id | sender_id | status | request_date | |---|---|---|---| | 101 | 1 | accepted | 2023-01-01 | | 102 | 1 | pending | 2023-01-05 | | 103 | 2 | accepted | 2023-02-01 | ### Example Output Explanation Alice sent 2 requests (101 and 102), Bob sent 1 request (103), and Carol sent none, so she doesn't appear in the output at all. Sorted by count descending, Alice (2) comes before Bob (1).
DROP TABLE IF EXISTS friend_requests; DROP TABLE IF EXISTS users; CREATE TABLE users (user_id INT, name VARCHAR(255)); CREATE TABLE friend_requests (request_id INT, sender_id INT, status VARCHAR(50), request_date DATE); INSERT INTO users VALUES (1, 'Alice'), (2, 'Bob'), (3, 'Carol'); INSERT INTO friend_requests VALUES (101, 1, 'accepted', '2023-01-01'), (102, 1, 'pending', '2023-01-05'), (103, 2, 'accepted', '2023-02-01');