それは本当に 変。代わりに、逆の順序で並べ替えてみましょう:
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';
プレ>
desc
に注意してください