One-to-one, one-to-many

One-to-one, one-to-many

You are an analyst at the Brightpath online school. There are three tables in the database: students — one row per student; student_profiles — a profile form, exactly one per student (a one-to-one relationship); enrollments — course sign-ups: a student may have several of them, or none at all (a one-to-many relationship). The curator needs a summary: which plan each student is on and how many courses they attend. Important: the profile form must not multiply a student's rows, and the absence of course sign-ups must not throw the student out of the report. Return the columns: - full_name — the student's name; - plan — the plan from the profile form; - courses_cnt — the number of course sign-ups (an integer; 0 if there are none). Sorting: courses_cnt descending, then full_name ascending. Students with no course sign-ups must be present in the result with the value 0.

Exemplo de resposta esperada

É assim que se parece uma resposta correta: ela tem seu próprio número de linhas e não precisa coincidir com as tabelas do esquema. Sua resposta precisa retornar os mesmos nomes de colunas do exemplo: use AS para renomeá-las se for preciso.

full_nameplancourses_cnt
Chloe Davispremium3
Alice Brownpremium2
Emma Fisherfree2
PostgreSQLv16
Entre para enviar

O resultado da sua consulta aparecerá aqui

Focus radio
Paused · SomaFM · Fluid