我在设置此查询并获得所需结果时遇到困难。我想通过SSN划分并计算借款人使用的人员数量。
这是到目前为止我已经走了多远
USE byte
GO
-- This creates a temporary table that you can reference for other queries
;WITH cteDupes AS
(
-- find all rows that have the same MobilePhone.
-- we consider those rows are duplicates so we partition on them
-- Order the partitioned group by most populated field, then by latest funding date
SELECT DENSE_RANK() OVER(Order By a.ssn) as ranked,
/*ROW_NUMBER() OVER(PARTITION BY FirstName, LastName, MobilePhone ORDER BY DateModified) AS RNA,*/
b.LoanOfficerUserName, a.SSN, concat(a.FirstName, ' ', a.LastName) as 'Borrower Name', a.homephone,
a.email, c.fundingdate
FROM borrower a
join byte.dbo.filedata b
on a.filedataid=b.filedataid
join byte.dbo.status c
on a.filedataid=c.filedataid
join byte.dbo.organization d
on b.organizationid=d.organizationid
where
d.code not in ('260%') and a.SSN not in ('null', '') and a.SSN not like '0000000%'
)
--Dedupe data and place it into a new table created
select * into contactdedupe.dbo.borrowerownership1
from cteDupes
这给我列出了SSN划分的所有借款人和rnd,基本上就像是1,2,3然后1,2,3,4表示单独的组。我如何将此显示为贷款人员的借款人数量。 谢谢,我试图使用一个没有运气的数据透视表
一个重点是我不想在报告中显示SSN字段
答案 0 :(得分:0)
Assigning a Row Number in SQL Server, but grouped on a value 这就是我想要的,一旦我能够分配一个'组号',我就可以在excel中使用数据透视表并获得所需的结果。谢谢大家的帮助