Hello people,
Is it possible to nest the SQL code before I write the data into DB? (picture below)

The code looks like:
with cte as
(
select
row_number() over
(
partition by
nbr
order by
nbr
,
(
case
when country=country_active then 1
when country=country_inactive then 2
else 3
end
)
,
(
case
when expiration_date_active >= expiration_date_inactive
then expiration_date_active
else expiration_date_inactive
end
) desc
) as rn
, *
from
[Sheet1$]
)
select * from cte
where rn = 1
order by nbrThank you in advance.