我有下表,需要以下输出-
doctor professor <--column names
tom mary
harry layla
这是我的查询无效-
select tb1.name, tb2.name from
(
select name
from tutorials.occupations
where occupation = 'doctor'
order by name
) tb1
inner join
(
select name
from tutorials.occupations
where occupation = 'professor'
order by name
) tb2
on tb1.name = tb2.name
答案 0 :(得分:2)
您不希望使用join
。您要union all
:
select doctor as name, 'doctor' as occupation
from t
union all
select professor as name, 'professor' as occupation
from t;
答案 1 :(得分:0)
select
doctor as name,
'doctor' as occupation
from
tb1
union all
select
professor as name,
'professor' as occupation
from
tb1;