Skip to content

Commit b76f2ed

Browse files
authored
Add files via upload
1 parent 1d49d7e commit b76f2ed

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
-- Question 105
2+
-- A U.S graduate school has students from Asia, Europe and America. The students' location information are stored in table student as below.
3+
4+
5+
-- | name | continent |
6+
-- |--------|-----------|
7+
-- | Jack | America |
8+
-- | Pascal | Europe |
9+
-- | Xi | Asia |
10+
-- | Jane | America |
11+
12+
13+
-- Pivot the continent column in this table so that each name is sorted alphabetically and displayed underneath its corresponding continent. The output headers should be America, Asia and Europe respectively. It is guaranteed that the student number from America is no less than either Asia or Europe.
14+
15+
16+
-- For the sample input, the output is:
17+
18+
19+
-- | America | Asia | Europe |
20+
-- |---------|------|--------|
21+
-- | Jack | Xi | Pascal |
22+
-- | Jane | | |
23+
24+
-- Solution
25+
select min(case when continent = 'America' then name end) as America,
26+
min(case when continent = 'Asia' then name end) as Asia,
27+
min(case when continent = 'Europe' then name end) as Europe
28+
from
29+
(select *, row_number() over(partition by continent order by name) as rn
30+
from student) a
31+
group by rn

0 commit comments

Comments
 (0)