Det er virkelig mærkelig. Lad os i stedet sortere i omvendt rækkefølge:
select replace(replace('count(distinct <thiscol>) over (partition by <nextcol>) / count(*) over () as <thiscol>_<nextcol>,',
'<thiscol>', column_name
), '<nextcol>', lead(column_name) over (order by column_id desc)
)
from all_tab_columns atc
where table_name = 'mytable';
Bemærk desc
i den slags.