业务表 Business
业务ID BusinessID
业务编码 BusinessCode
业务名称 BusinessName
集团名称 GroupName
业务类型 BusinessType
承载类型ID BearerTypeID
记录创建时间 CreatedOn
记录修改时间 ModifiedOn
员工表 Employee
员工ID EmployeeID
组ID EmployeeGroupID
用户名 EmployeeUsername
密码 EmployeePassowrd
员工姓名 EmployeeName
员工电话 EmployeeTel
员工状态 EmployeeStatus
员工职位 EmployeePosition
所在部门 EmployeeDepartment
记录创建时间 CreatedOn
记录修改时间 ModifiedOn
网服表 ServiceManage
网服ID ServiceManagerID
业务ID BusinessID
员工ID EmployeeID
关系 Relation (1,2,3)
要的结果
业务名称 集团名称 Relation =1员工姓名 Relation =2 员工姓名 Relation =3 员工姓名
SELECT bu.BusinessName, (SELECT em.EmployeeName FROM ServiceManager sm LEFT JOIN Employee em ON sm.EmployeeID = em.EmployeeID WHERE sm.BusinessID = bu.BusinessID and sm.Relation = 1) AS ServiceManageNameA, (SELECT em.EmployeeName FROM ServiceManager sm LEFT JOIN Employee em ON sm.EmployeeID = em.EmployeeID WHERE sm.BusinessID = bu.BusinessID and sm.Relation = 2) AS ServiceManageNameB, (SELECT em.EmployeeName FROM ServiceManager sm LEFT JOIN Employee em ON sm.EmployeeID = em.EmployeeID WHERE sm.BusinessID = bu.BusinessID and sm.Relation = 3) AS ServiceManageNameC FROM Business bu
刚自己想了个,不过有问题求改
Oo浮云oO
Mr_Li_0001