我有以下选择(它将更多联盟):
select column_name,'my_table', count(*)
from my_table
where col10 = 'TEST'
group by column_name
having count(*) > 1
union all
select column_name,'my_table2', count(*)
from my_table2
where col10 = 'TEST'
group by column_name
having count(*) > 1
union all...;
运行语句后,我从my_table2 获得 0行。
然后可以显示如下所示的内容?
答案 0 :(得分:1)
为每个表添加另一个UNION ALL
union all
select '-', 'my_table2', 0
from dual
where not exists
(
select 1
from my_table2
where col10 = 'TEST'
group by column_name
having count(*) > 1
)
答案 1 :(得分:1)
也许是这样的:
select nvl(sq.column_name, '-') as column_name, tn.table_name,
nvl(sq."count > 1", 0) as "count > 1"
from (
select "my_table" as table_name from dual union all
select "my_table2" from dual -- [ ... union all ... etc]
) tn
left outer join
(
-- ENTER YOUR CURRENT QUERY HERE, AS A SUBQUERY
) sq
on tn.table_name = sq.table_name
;