我有一个查询,我试图在 SQL Server 2008 中编写以生成如下行:
quoteID | dateEntered | insuredName | agentName | quoteType | status | noteDate | userType
我目前有:
SELECT
t1.quoteID,
t1.dateEntered,
t1.insuredFirstName + ' ' + t1.insuredLastName as insuredName,
t2.FirstName + ' ' + t2.LastName as agentName,
t1.quoteType,
t1.status,
t3.noteDate
FROM
quote_genericInformation t1
INNER JOIN tbl_agents t2
ON t1.createUserID = t2.AgentNumber
INNER JOIN
(SELECT quoteID, MAX(dateEntered) as noteDate
FROM quote_notes GROUP BY quoteID) t3
ON t1.quoteid = t3.quoteid
ORDER BY t1.quoteID
这会产生如下结果:
quoteID | dateEntered | insuredName | agentName | quoteType | status | noteDate
54 | 01/01/2000 | First Last | First Last | apptype | open | 01/01/2000
- 我需要将用户类型添加为另一列,但是当我添加它时,我开始重复。
- 无论该quoteID是否存在quote_note,我都需要它始终显示一行
- 我需要这个来在注释中显示最新的用户类型(基于注释)
谢谢!