Oracle 动态数据的动态查询

Oracle 动态数据的动态查询,oracle,dynamic,Oracle,Dynamic,我是oracle数据库的新手,我正在尝试执行以下查询 select o.id as ovaid , (case when(select count(m.cid) from ovamapper m where m.id = o.id and m.solutionid = 1)>0 then 1 else 0 end) as sol1, (case when(select count(m.cid) from ovamapper m where m.id = o.id and m.solutio

我是oracle数据库的新手,我正在尝试执行以下查询

select o.id as ovaid ,
(case when(select count(m.cid) from ovamapper m where m.id = o.id and m.solutionid = 1)>0 then 1 else 0 end) as sol1,
(case when(select count(m.cid) from ovamapper m where m.id = o.id and m.solutionid = 2)>0 then 1 else 0 end) as sol1,
(case when(select count(m.cid) from ovamapper m where m.id = o.id and m.solutionid = 3)>0 then 1 else 0 end) as sol1 from ovatemplate o order by o.id
我想从其他表中选择solutionid,而不是它的静态值

非常感谢您在这方面提供的任何帮助

加入

到包含solutionid的表。前

Select * from ovatemplate JOIN solutiontable ON (solutiontable.ovaid=ovatempate.ovaid) 
然后,将静态值更改为solutionid

尝试此查询

select  o.id as ovaid ,
        count(case when solutionid = 1 then m.cid else null end) as sol1 , 
        count(case when solutionid = 2 then m.cid else null end) as sol2 , 
        count(case when solutionid = 3 then m.cid else null end) as sol3
from    ovamapper m , ovatemplate o
where   m.id = o.id
group by o.id
order by o.id
如果您不需要将聚合作为列,那么您可能应该这样做

select  o.id as ovaid , solutionid , count(*) as sol
from    ovamapper m , ovatemplate o
where   m.id = o.id
and     m.solutionid in (1,2,3)
group by o.id , solutionid
order by o.id

请提供表模式以了解更多信息感谢您的回复…但在上面的查询中,SolutionID是静态的。。。我希望solutionid来自不同的表,如“从表2中选择solutionid”