oraclesql中的Replace函数
我正在使用oracle SQL,我有以下查询:oraclesql中的Replace函数,sql,oracle,replace,Sql,Oracle,Replace,我正在使用oracle SQL,我有以下查询: select replace(replace('count(distinct <thiscol>) over (partition by <nextcol>) / count(*) over () as <thiscol>_<nextcol>,', '<thiscol>', column_name )
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)
)
from all_tab_columns atc
where table_name = 'mytable'
我希望得到的不是:
count(distinct name2) over (partition by name3) / count(*) over ()
此查询:
count(distinct name3) over (partition by name2) / count(*) over ()
任何人都可以建议如何替换列值的顺序?(
和
)。我试图用
替换
,但它给了我同样的结果。我尝试了许多其他的事情,取得了成功
有人吗?真奇怪。相反,让我们按相反的顺序排序:
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';
选择replace(replace('count(distinct)over(partition by)/count(*)over()as quot,
'',列名称
),'',领先(列名称)超过(按列id描述排序)
)
从所有选项卡栏atc
其中table_name='mytable';
注意排序中的
desc
。您得到了什么输出,以及它与您想要的有什么不同?另外,请用人类语言(而不是SQL)对您试图实现的目标进行解释。完成。希望足够清楚。然后可能需要使用LAG
而不是LEAD
?只有over()中的值已更改。另一个没有。@GordonLinoff.你太棒了!非常感谢你!我从你身上学到了很多。非常感谢!
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';