string sql = @"select (case t.isreturn when 1 then 1 else 0 end) as isreturn,a.Dept,a.Major,a.class from
(
select parentid,isreturn from [dbo].[Acc_DormitoryBuild] where BuildType='5' and (studentid is not null and len(studentid)>0)
select parentid,isreturn from [dbo].[Acc_DormitoryBuild] where BuildType='5' and (studentid is not null and len(studentid)>0) and (IsReturn is not null and len(IsReturn)>0)
) t
join Acc_DormitoryBuild a on a.ID=t.parentid where 1=1