I have a script here to get all account numbers that have multiple owners but I want to remove those rows which present 1 account_number = 1 account_owner. I want to get records that present 1 account_number >= one account_owner.
select ACCT_NUMBER, ACCT_OWNER from [DW].[ACCT DETAILS] WITH(NOLOCK)
where ACCT_NUMBER in (select distinct(ACCT_NUMBER)
from [DW].[TDMA_DIM_DETAILS] WITH(NOLOCK)
group by ACCT_NUMBER
)
group by ACCT_NUMBER, ACCT_OWNER
Here are the results..
ACCT_NUMBER ACCT_OWNER
1359180 Spearman, John
1359190 Grifman, Karen
1359210 Spearman, John
1359220 Adams, Craig
1359220 Biga, Lou
1359220 Wright, Gerald
1359230 Levine, Renee
1359250 Reitwiesner, John
1359260 Skowronski, Cindi
1359510 Cordova, Diana
1359510 Macfarlane, Linda
1359510 Marquez, Suzanne
I was hoping to see results like the one I got from account numbers 1359220 and 1359510, because there are also other account numbers that have multiple owners.
I've tried using having(count(distinct ACCT_OWNER) >1 but it didn't help.
account_numberis associated with severalaccount_owners. If so, you could do a subquery selectingaccount_numberandcount(account_owner)where the count > 1, and use that to filter the main query using eitherwhereorjoin.