select t.class_name className,t.id classId, t2.id vipId,t2.child_name childName,t2.img_url imgUrl,t2.grade,t2.sex,t2.school,IF(t3.mobile is null,t2.phone,t3.mobile) phone, case when t4.stat = 2 or t4.stat is null then -1 else 0 end as correctType, case when t4.stat = 2 or t4.stat is null then 1 else 0 end sort_no from tb_lib_vip t2 left join (select tc.class_name,tc.id,tcs.vip_id from tb_class_student tcs,tb_class tc where tcs.status in (1,2) and tcs.lib_id=#{libId} and tc.status=1 and tcs.class_id=tc.id ) t on t2.id=t.vip_id left join tb_user t3 on t2.user_id=t3.id left join tb_lib_vip_service t4 on t2.id = t4.vip_id and t4.type='C025' and t4.species='S003' where 1=1 and t4.lib_id=#{libId}