0
我使用Oracle SQL,和我有以下查询:用Oracle SQL替换功能
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'
应该是查询,如按照输出:
select id,
count(distinct name2) over (partition by name3)/count(*) over(),
count(distinct name3) over (partition by name4)/count(*) over(),
. . .
from mytable;
我期待得到的,而不是:
count(distinct name2) over (partition by name3)/count(*) over()
此查询:
count(distinct name3) over (partition by name2)/count(*) over()
任何人都可以建议如何替换列值的顺序? (<thiscol>
和<nextcol>
)。我试图用<nextcol>
替换<thiscol>
,但它给了我相同的结果。我尝试了很多成功的事情。
有人吗?
你会得到什么样的输出以及与你想要的不同?请用人类语言添加解释,而不是SQL,解释您正在尝试实现的内容。 – mustaccio 2014-12-03 15:37:43
完成。希望它很清楚。 – Omri 2014-12-03 15:42:26
那么你可能需要使用'LAG'而不是'LEAD'? – mustaccio 2014-12-03 15:46:19