这已经解决了,我需要将 SQL 中的 4 个表与不同表中的 2 列连接为不同的。直到现在,我一直会得到重复的行。
我有 4 个表,我试图加入 1 个查询。
我需要创建一个如下所示的报告:
quoteid | dateEntered | insuredName | admin initials | quoteType | status | last note usertype
Select quoteID,insuredFirstName,insuredLastName,quoteType,status, firstname, lastname, adminInitial, userType
from (SELECT Row_Number() Over(Partition by A.quoteid order by A.quoteid ) as Row , A.quoteID, A.insuredFirstName, A.insuredLastName, A.quoteType, A.status, B.firstName, B.lastName, left(C.firstName,1) + left(C.lastName,1) as adminInitial, D.userType
FROM quotes A
INNER JOIN tbl_agents B
ON A.createUserID = B.AgentNumber
INNER JOIN tbl_admins C
ON A.assignedID = C.ID
INNER JOIN
(SELECT
quoteID, userType
FROM quote_notes) D
ON A.quoteID = D.quoteID) as t where row=1