我正在尝试:
当我在SELECT中使用以下Case时,Student_Name和amp; Faculty_Name都为null:
select a2.id as Case_Id,
case when a1.id=a2.Student_Id then a1.name end as Student_Name,
case when a1.id=a2.Faculty_Id then a1.name end as Faculty_Name
from account a1, case a2
我从下面的SQL中知道a1.Id = a2.Student_Id + a1.Id = a2.Faculty_Id:
select a2.id, a1.name
from account a1, case a2
where a1.id=a2.Student_Id
为什么我没有得到列“Student_Name”,“Faculuty_Name”的任何想法都是空的?我正在使用Claudera Hadoop。
答案 0 :(得分:0)
如果您尝试获取两列的名称,则可以执行以下操作:
select c.id as Case_Id, a1.name as Student_Name, a2.name as Faculty_Name
from case c account c left join
account a1
on c.student_id = a1.id left join
account a2
on c.faculty_id = a2.id;
这是我对你要做的事情的最好解释。