我可以计算每列的不同值而不枚举它们吗?
假设我有一张桌子col1
, col2
, col3
,并且没有其他列。在不明确提及这些列的情况下,我希望得到与以下相同的结果:
SELECT
count(distinct col1) as col1,
count(distinct col2) as col2,
count(distinct col3) as col3
FROM mytable;
我怎样才能做到这一点 ?
我认为使用普通 SQL 可以轻松做到的最好的事情就是运行这样的查询来生成您想要的查询,然后运行它。
select 'select count(distinct '
|| listagg(column_name || ') as ' || column_name, ', count(distinct ') within group (order by column_id)
|| ' from ' || max(table_name) || ';' as script
from all_tab_cols
where table_name = 'MYTABLE';
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)