Social Network Relationship Statistics
Problem statement
Generate a report of social-network profiles and their relationship statistics.
Return one row for every profile with these columns in order:
full_name, formatted aslast_name, one space, thenfirst_name.email.total_relations, the total number of rows inrelationsfor the profile.approved_relations, the number of relationships whoseis_approvedvalue istrue.pending_relations, the number of relationships whoseis_approvedvalue isfalse.
Profiles with no relationship rows must still appear with all three counts equal to 0. Sort the result by full_name in ascending order, then by email in ascending order when full names are equal.
Table schema
MySQLPostgreSQLPandas
Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.
profiles
Social-network profile records.
| Column | Type | Nullable | Description |
|---|---|---|---|
| idPK | Integer | No | Profile ID. |
| first_name | Text | No | Profile first name. |
| last_name | Text | No | Profile last name. |
| Text | No | Profile email address. |
relations
Relationship rows belonging to profiles.
| Column | Type | Nullable | Description |
|---|---|---|---|
| profile_id | Integer | No | Profile that owns the relationship. |
| related_to | Text | No | Identifier of the related profile or account. |
| is_approved | Boolean | No | Whether the relationship is approved. |
Foreign key: profile_id → profiles(id)
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| full_name | Text | No | — |
| Text | No | — | |
| total_relations | Integer | No | — |
| approved_relations | Integer | No | — |
| pending_relations | Integer | No | — |
Row order: must match exactly. Numeric tolerance: 0.
Constraints
profiles.idis unique and identifies one profile.- Every
relations.profile_idreferences an existingprofiles.id. relations.is_approvedis eithertrueorfalse.- Each row in
relationscounts as one relationship, even whenrelated_tovalues repeat. - Profiles with no relationship rows have zero total, approved, and pending relationships.
- Rows with equal
full_namevalues are ordered byemailin ascending order.