select id from (select id, row_number() over(order by id asc) from tricky_sort where id>=0 union select id, row_number() over(order by id desc) + (select count(1) from tricky_sort where id>=0 ) from tricky_sort where id
with cte as( select numbers.*,ROW_NUMBER()OVER() as x1,'A' as val FROM numbers where ID>=0 ORDER BY ID ),cte1 as( select numbers.*,ROW_NUMBER()OVER() as x2,'b' as val FROM numbers where ID
select id from (select id, row_number() over(order by id asc) from tricky_sort where id>=0 union select id, row_number() over(order by id desc) + (select count(1) from tricky_sort where id>=0 ) from tricky_sort where id
Good... understand your approach.. think any other way to solve this..
with cte as(
select numbers.*,ROW_NUMBER()OVER() as x1,'A' as val FROM numbers where ID>=0 ORDER BY ID
),cte1 as(
select numbers.*,ROW_NUMBER()OVER() as x2,'b' as val FROM numbers where ID
@HARSHRAJ-gp6ve good but always think for simple solution.
Hint: CASE WHEN statement comes handy in these scenarios.
select id from
(select id,1 as num from num_order where id>=0
union
select id,2 as num from num_order where id
Orderby doesn't work in union/sub queries