- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_618.sql
12 lines (10 loc) · 663 Bytes
/
_618.sql
1
2
3
4
5
6
7
8
9
10
11
12
--reference: https://discuss.leetcode.com/topic/92752/accept-solution and https://leetcode.com/articles/students-report-by-geography/#approach-using-session-variables-and-join-accepted
set @a =0;
set @b =0;
set @c =0;
SelectAmerica.nameas America, Asia.nameas Asia, Europe.nameas Europe from
(select name, @a := @a +1as id from student where continent ='America'order by name) as America
Left Join
(select name, @b := @b +1as id from student where continent ='Asia'order by name) as Asia onAmerica.id=Asia.id
Left Join
(select name, @c := @c +1as id from student where continent ='Europe'order by name) as Europe onAmerica.id=Europe.id