FROM rb_manager AS A LEFT JOIN rb_school AS B ON A.School_Id=B.SId
LEFT JOIN rb_account AS account ON (A.MId=account.AccountId and account.AccountType=1)
SELECT A.* ,IFNULL(G.GroupName,'') AS GroupName,IFNULL(s.SName,'') AS SchoolName
,IFNULL(d.DeptName,'') AS DeptName,IFNULL(p.PostName,'') AS PostName
FROM
(
SELECT A.MId AS TabKeyId,A.MName AS EmployeeName,A.School_Id,A.Group_Id,A.Dept_Id,A.Post_Id,IFNULL(A.Sex,0) AS Sex,A.MTel AS EmployeePhone,A.BirthDate,A.Education,A.LeaveStatus,A.LeaveTime
, 1 AS AccountType,IFNULL(B.Account,'') AS Account,IFNULL(B.Id,0) AS EmployeeId,A.MHead AS EmployeeIcon,A.EntryTime
FROM rb_manager AS A LEFT JOIN rb_account AS B ON A.MId=B.AccountId AND B.AccountType=1
UNION ALL
SELECT A.TId AS TabKeyId,A.TeacherName AS EmployeeName,A.School_Id,A.Group_Id,A.Dept_Id,A.Post_Id,IFNULL(A.Sex,0) AS Sex,A.TeacherTel AS EmployeePhone,A.BirthDate,A.Education,A.LeaveStatus,A.LeaveTime
,2 AS AccountType,IFNULL(B.Account,'') AS Account,IFNULL(B.Id,0) AS EmployeeId,A.TeacherHead AS EmployeeIcon,A.EntryTime
FROM rb_teacher AS A LEFT JOIN rb_account AS B ON A.TId=B.AccountId AND B.AccountType=2
UNION ALL
SELECT A.AId AS TabKeyId,A.AssistName AS EmployeeName,A.School_Id,A.Group_Id,A.Dept_Id,A.Post_Id,IFNULL(A.Sex,0) AS Sex,A.AssistTel AS EmployeePhone,A.BirthDate,A.Education,A.LeaveStatus,A.LeaveTime
,3 AS AccountType,IFNULL(B.Account,'') AS Account,IFNULL(B.Id,0) AS EmployeeId,A.AssistIcon AS EmployeeIcon,A.EntryTime
FROM rb_assist AS A LEFT JOIN rb_account AS B ON A.AId=B.AccountId AND B.AccountType=3
) AS A LEFT JOIN rb_group AS g ON A.Group_Id=g.GId
LEFT JOIN rb_school AS s ON A.School_Id=s.SId
LEFT JOIN rb_department AS d ON A.Dept_Id=d.DeptId