bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 618. Students Report By Geography

618. Students Report By Geography

Leetcode Solutions

Pivoting Student Table by Continent with Session Variables

  • Initialize session variables for each continent to keep track of row numbers.
  • Create subqueries for each continent that select students' names and assign row numbers using session variables, ordered alphabetically by name.
  • Perform a RIGHT JOIN between the Asia and America subqueries on their respective row numbers.
  • Perform a LEFT JOIN between the result of the previous join and the Europe subquery on the America row number.
  • Select the final columns America, Asia, and Europe from the joined tables to form the final result.
erDiagram
    Student {
        varchar name
        varchar continent
    }

Pivoting Student Table by Continent with Conditional Aggregation

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...