I need to find duplicates in one table and then join those results with another table to calculate the number of clients by ClientType.
Here is the query that identifies the duplicates:
with cte as (
select t.ID,
t.screeningdate,
t.Jurisdiction,
t.name,
t.clientid,
t.submitdate,
count(*) over (partition by ClientID) as dup_count
from tblTest t
)
select *
from cte
where dup_count > 1
and submitdate between '06/01/2024' and '06/30/2024'
Here are the results from this query:
Here is the table that needs to be joined, calculate the number of clients and group by the Client Type:
SELECT [ID]
,[FirstName]
,[LastName]
,[MiddleInt]
,[CLIENTID]
,[COUNTYID]
,[SUBMITDATE]
,[ClientType]
FROM [dbo].[tblClient]
This is what the results should look like:
ClientType | NumScreened |
---|---|
1 | 2 |
2 | 5 |
3 | 18 |
Thanks.