本帖最后由 baobao28 于 2012-11-15 09:00:33 编辑 有这么一个查询语句如下,我想把这个查询做成一个视图在程序中调用,但是where那部分是我想要传递的查询条件,如果我把这个查询语句做成视图以后,怎么能把查询条件传递进去
with aa as
(select t.code, t.code_name from code t where t.code_type_id = 12),
bb as
(select t2.apply_type, t2.hospital_id, sum(cf.fee_amount) fee
from consult_fee cf
left join consult_booking t2
on cf.booking_id = t2.id
group by t2.apply_type, t2.hospital_id)
select t4.hospital_name, aa.code_name, t.counts, bb.fee, t4.balance
from (select t2.apply_type, t2.hospital_id, count(t1.id) counts
from consult_report t1
left join consult_booking t2
on t1.consult_booking_id = t2.id
left join consult_fee t3
on t2.id = t3.booking_id
left join doctor_info t4
on t1.expert_id = t4.id
where t1.consultation_status in (6, 7)
and t4.at_hospital_id = 100
and t2.hospital_id = 1
and t1.CONSULTATION_TIME between
to_date('2012-01-01', 'yyyy-mm-dd') and sysdate
group by t2.apply_type, t2.hospital_id) t
left join aa
on t.apply_type = aa.code
left join bb
on t.apply_type = bb.apply_type
left join hospital_info t4
on t.hospital_id = t4.id;
------最佳解决方案--------------------
这样能传多个条件么?
------其他解决方案--------------------
視圖本身不需查詢倏件限制,只需關聯倏件就好了,創建完視圖後,根據你的查詢倏件,直接從視圖中加where取出即可
------其他解决方案--------------------
这样不行啊,因为这个查询里面那层是进行数据统计计算的,如果不把条件在里面加上的话,在外面加就没有意义了啊
------其他解决方案--------------------
你创建的视图里增加带where的字段,然后创建视图,再select * from 视图 where 条件。
------其他解决方案--------------------
拜托大家仔细帮忙看一下,and t2.hospital_id = 1这个可以拿出来放到上面那个select里面,但是剩下这2个查询条件就拿不出来了啊,因为用到了最内层的主表作为关联的
and t4.at_hospital_id = 100
and t1.CONSULTATION_TIME between
to_date('2012-01-01', 'yyyy-mm-dd') and sysdate
------其他解决方案--------------------