6内部联合错了?

时间:2017-04-15 01:55:18

标签: sql-server adventureworks

我的教授告诉我,我需要使用6 INNER JOINs来连接这些表格上的信息,但我在某个地方搞砸了。我没有看到其他任何有要加入的departmentID的地方。那我该怎么办?

USE AdventureWorks2014

GO

CREATE FUNCTION ContactList()

RETURNS TABLE

AS

RETURN 
(
    SELECT  p.BusinessEntityID,LastName + ',' + FirstName AS Employee,
            ea.EmailAddress, jt.JobTitle, pp.PhoneNumber, 
            pp.PhoneNumberTypeID, pt.Name AS Type, hrd.Name AS Department
    FROM Person.Person as p
    INNER JOIN Person.EmailAddress ea
        ON ea.BusinessEntityID = p.BusinessEntityID
    INNER JOIN HumanResources.Employee jt
        ON jt.BusinessEntityID = p.BusinessEntityID
    INNER JOIN Person.PersonPhone pp
        ON pp.BusinessEntityID = p.BusinessEntityID
    INNER JOIN Person.PhoneNumberType pt
        ON pt.PhoneNumberTypeID = pp.PhoneNumberTypeID
    INNER JOIN HumanResources.Department hrd
        ON hrd.DepartmentID = P.BusinessEntityID
    INNER JOIN Person.PhoneNumberType
        ON pt.Name = hrd.Name
)

GO

0 个答案:

没有答案