首页 > 解决方案 > 交叉连接表以查看一个表中的哪些合作伙伴有另一个表中的报告

问题描述

SX 新手,刚开始深入研究编程世界,可以在这个问题上使用一些帮助。

我需要找出 MentorRelations 表中的哪些合作伙伴组在报告表中没有报告。到目前为止,我只设法交叉加入员工和学员/导师代码,以找出员工的姓名和他们所属的组。(员工代码 = 导师/导师代码)

我在 SQL Server 管理工作室环境中工作。

我正在使用的表格很简短;MentorRelationship [menteecode,relationshipcode,mentorcode]

Employee
[EmployeeID, EmployeeCode, Firstname,lastname]

UserReport 
[reportID, employeeID]

Report
[ReportID, name, reportgroupID]

到目前为止,我制定的代码是;

SELECT
m.menteeCode,
E1.firstname AS Mentee_FN,
E1.lastname AS Mentee_LN,
m.mentorCode,
E2.firstname AS Mentor_FN,
E2.lastname AS Mentor_LN,
FROM
MentorRelationshipStaging m 
INNER JOIN Employee e1
         ON e1.EmployeeCode = m.MenteeCode
INNER JOIN Employee e2
         ON e2.EmployeeCode = m.MenteeCode
ORDER BY m.MenteeCode

在此之后我很困惑,非常感谢答案或解决此问题的下一步。我也将继续研究我的目的。

PS我在这里上传了我正在使用的数据库的图表:
https ://m.imgur.com/a/9JMRpFw

标签: sqlsql-serverquery-optimization

解决方案


推荐阅读