I am trying to filter max(row_number). But getting errors. over partition by... order by code_description desc does not work for me. I have to get last code_id description. Right we can't keep aggregate function on where condition.I have imported records from excel
Help is much appreciated.
Expectation
Code_Id Code_description 10000, Maintain healthy bone,teeth and increase immune
My code is:
Create table #test 
(
    code_id int,
    Code_description varchar(100)
)
insert into #test values (10000, 'Maintain healthy bone')
insert into #test values (10000, 'Maintain healthy teeth')
insert into #test values (10000, 'Increases Immune')
insert into #test values (10000, 'Maintain healthy bone,teeth and increase immune')
With cte as
(
    select 
        code_id, Code_description,
        row_number() over (partition by code_ID order by code_id) rn
    from 
        #test
)
select * 
from cte 
where rn = max(rn)
group by code_id, Code_description
