i do not think James SQL is right .. please excuse me James
Need to get ACCOUNT that has more than one unique PARTNER & ADDRS_NUM are different.
create data script
drop table if exists #DATA
create table #DATA(ACCOUNT varchar(10) ,PARTNER varchar(10) ,ADDRS_NUM varchar(10) )
insert into #DATA select 'HL124','2341','ASD123'
insert into #DATA select 'HL124','2341','SDF234'
insert into #DATA select 'HL124','234N','SDF234'
insert into #DATA select 'HG225','45BV','QWE345'
insert into #DATA select 'HG225','72AA','QWE345'
insert into #DATA select 'UY150','8846','CCC204'
select
ACCOUNT
, partner
, sum(case when Partner <> ADDRS_NUM then 1 else 0 end) from #DATA
group by
ACCOUNT, partner
having
sum(case when Partner <> ADDRS_NUM then 1 else 0 end) > 1
; with cte as
(
select
ROW_NUMBER () OVER (partition by account , Partner order by addrs_num) as rn ,
*
FROM
#DATA
)
select
Account
from
( select * from cte where rn = 1 ) a
group by
Account
having
min(addrs_num) <> max(addrs_num)