How to avoid “multiple” groups in SQL

I have the following code:

select id as customerid,
tempo.team,
max(cast(t.transaction_date as date)) as latest_transaction
from custom.tdc_unique_members tum 
left join tdc."transaction" t 
    on t.transaction_patron_account_id = tum.simple_id 
left join tdc.agency a 
    on a.agency_id = t.agency_id
left join 
(
select agency.agency_code, supp.description,
 case 
    when agency.description like '%Augusta%' or agency.description like '%GreenJackets%' or agency.agency_code like '%AGJ%' then 'Augusta GreenJackets'
    when agency.description like '%Iowa%' or agency.description like '%Cubs%' then 'Iowa Cubs'
    when agency.description like '%San Jose%' or agency.description like '%Giants%' or agency.description like 'SJG%' then 'San Jose Giants'
    when agency.description like '%Memphis%' or agency.description like '%Redbirds%' then 'Memphis Redbirds'
    when agency.description like '%Midland%' or agency.description like '%RockHounds%' or agency.description like 'SJG%' then 'Midland RockHounds'
    when agency.description like '%Inland Empire%' or agency.description like '%66ers%' or agency.description like 'IE%' then 'Inland Empire 66ers'
    when agency.description like '%Winston-Salem%' or agency.description like '%Dash%' or agency.description like 'WSD%' or agency.agency_code like '%WSD%' then 'Winston-Salem Dash'
    else supp.description 
end as team
    from tdc.agency agency
left join tdc.supplier_agency supag
    on supag.agency_id = agency.agency_id 
left join tdc.supplier supp
    on supp.supplier_id = supag.supplier_id  
)tempo on tempo.agency_code = a.agency_code
where team is not null
group by customerid, tempo.team

and use the following code to check data

select id as customerid,
tempo.team,
max(cast(t.transaction_date as date)) as latest_transaction
from custom.tdc_unique_members tum 
left join tdc."transaction" t 
    on t.transaction_patron_account_id = tum.simple_id 
left join tdc.agency a 
    on a.agency_id = t.agency_id
left join 
(
select agency.agency_code, supp.description,
 case 
    when agency.description like '%Augusta%' or agency.description like '%GreenJackets%' or agency.agency_code like '%AGJ%' then 'Augusta GreenJackets'
    when agency.description like '%Iowa%' or agency.description like '%Cubs%' then 'Iowa Cubs'
    when agency.description like '%San Jose%' or agency.description like '%Giants%' or agency.description like 'SJG%' then 'San Jose Giants'
    when agency.description like '%Memphis%' or agency.description like '%Redbirds%' then 'Memphis Redbirds'
    when agency.description like '%Midland%' or agency.description like '%RockHounds%' or agency.description like 'SJG%' then 'Midland RockHounds'
    when agency.description like '%Inland Empire%' or agency.description like '%66ers%' or agency.description like 'IE%' then 'Inland Empire 66ers'
    when agency.description like '%Winston-Salem%' or agency.description like '%Dash%' or agency.description like 'WSD%' or agency.agency_code like '%WSD%' then 'Winston-Salem Dash'
    else supp.description 
end as team
    from tdc.agency agency
left join tdc.supplier_agency supag
    on supag.agency_id = agency.agency_id 
left join tdc.supplier supp
    on supp.supplier_id = supag.supplier_id  
)tempo on tempo.agency_code = a.agency_code
where team is not null
and customerid like '401820%'
group by customerid, tempo.team

but get the following ouput

401820|AUG Augusta GreenJackets 2023-09-03
401820|POR Wichita Wind Surge 2023-09-13
401820|MEM Augusta GreenJackets 2023-09-03
401820|MEM Wichita Wind Surge 2023-09-13
401820|MEM Memphis Redbirds 2023-08-31
401820|WIC Wichita Wind Surge 2023-09-13
401820|WIC Memphis Redbirds 2023-08-31
401820|AUG Portland Sea Dogs 2023-08-29
401820|AUG Wichita Wind Surge 2023-09-13
401820|AUG Memphis Redbirds 2023-08-31
401820|POR Augusta GreenJackets 2023-09-03
401820|POR Portland Sea Dogs 2023-08-29
401820|POR Memphis Redbirds 2023-08-31
401820|MEM Portland Sea Dogs 2023-08-29
401820|WIC Augusta GreenJackets 2023-09-03
401820|WIC Portland Sea Dogs 2023-08-29

I only want one customer ID and team and each customer ID is associated with a team. For example, my desired output would be

401820|WIC Wichita Wind Surge 2023-09-13
401820|POR Portland Sea Dogs 2023-08-29
401820|MEM Memphis Redbirds 2023-08-31
401820|AUG Augusta GreenJackets 2023-09-03

Why am I not getting that? I feel it is something in the grouping but I can’t figure it out.

I only want one customer ID and team and each customer ID is associated with a team. For example, my desired output would be

401820|WIC Wichita Wind Surge 2023-09-13
401820|POR Portland Sea Dogs 2023-08-29
401820|MEM Memphis Redbirds 2023-08-31
401820|AUG Augusta GreenJackets 2023-09-03

New contributor

CoolBeans87 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật