, используя CTE
и self join
, чтобы получить count
, который больше 1.
Вы можете попробовать это.
;with CTE AS (
SELECT
A.Payer,
A.PaymentDate,
A.Name
FROM (
SELECT
T.InstitutionRoleXrefLongName AS 'Payer',
T.PaymentDate AS 'PaymentDate',
T.FullName AS 'Name'
FROM Transfer T
UNION ALL
SELECT
T.InstitutionRoleXrefLongName AS 'Payer',
T.PaymentDate AS 'PaymentDate',
T.FullName AS 'Name'
FROM TransferClosed T
) A
WHERE PaymentDate Between '20180101' AND '20180331 23:59:59'
)
select t2.*
from (
SELECT name,count(1) totle
FROM CTE
GROUP BY Name
) t1 inner join CTE t2
ON t1.totle > 1 and t1.Name = t2.Name
sqlfiddle CTE
макет вашего набора результатов
sqlfiddle: http://sqlfiddle.com/#!18/cc68f/9