输入表格
输出样式
Jenny Ashley Meera Jane
Samantha Christeen Priya Julia
NULL Ketty NULL Maria
ps:(第一列是一个按字母顺序排序列表医生的名字。
第二列是一个按字母顺序排序列表教授的名字。
第三列是一个按字母顺序排序列表歌手的名字。
第四列是一个按字母顺序有序列表的演员的名字。
列的空单元格数据小于最大数量每个职业的名称(在本例中,教授和演员列)充满了空值。)
代码如下:
set @r1=0, @r2=0, @r3=0, @r4=0; select min(Doctor), min(Professor), min(Singer), min(Actor) from( select case when Occupation='Doctor' then (@r1:=@r1+1) when Occupation='Professor' then (@r2:=@r2+1) when Occupation='Singer' then (@r3:=@r3+1) when Occupation='Actor' then (@r4:=@r4+1) end as RowNumber, case when Occupation='Doctor' then Name end as Doctor, case when Occupation='Professor' then Name end as Professor, case when Occupation='Singer' then Name end as Singer, case when Occupation='Actor' then Name end as Actor from OCCUPATIONS order by Name ) Temp group by RowNumber