视图只是一张虚表,只是逻辑上存在的一张表。你每次获取视图时,实际上还是需要数据库执行一边创建视图的搜索语句的。所以在执行效率上并没有任何好处。
视图的好处就是在你做复杂的查询逻辑时可以简化你的思考过程,比如你有一个查询语句需要select a.a, a.b from (select x a, y b from t where ....) a where ......你可以把内部的select 语句变成view,这样整个语句会变成select v.a, v.b from v where .....对你思考查询逻辑有利。
[Quote=引用 1 楼 g13051407191 的回复:]
select item.id,item.name2,mt.id,mt.name,mt.itemtype,mtd.id,mtd.name
,mtd.methodsource,aa.iscertified,aa.certifiedname,aa.personnum,aa.id,aa.ORGID,
mtd.apptype,mtd.creator from itemtype
item left join monitoritems mt on item.id=mt.itemtype left join
monitormethods mtd on mt.id=mtd.itemtype left join (select mtf.id,mtf.MONITORMETHODID,
mtf.iscertified,mtf.certifiedname,mtf.personnum,mtf.ORGID from monitoritemsinfo mtf
where mtf.creator='hebeidata' and mtf.orgid='2147' ) aa on
mtd.id=aa.MONITORMETHODID where item.id='10100' order by mtd.creator
CREATE VIEW id1,name2,id2,name,itmetype,id3,name3,methodsource,iscertified,certifiedname,personnum
,id4 ,ORGID,apptype,creator
AS
select item.id,item.name2,mt.id,mt.name,mt.itemtype,mtd.id,mtd.name
,mtd.methodsource,aa.iscertified,aa.certifiedname,aa.personnum,aa.id,aa.ORGID,
mtd.apptype,mtd.creator from itemtype
item left join monitoritems mt on item.id=mt.itemtype left join
monitormethods mtd on mt.id=mtd.itemtype left join (select mtf.id,mtf.MONITORMETHODID,
mtf.iscertified,mtf.certifiedname,mtf.personnum,mtf.ORGID from monitoritemsinfo mtf
where mtf.creator='hebeidata' and mtf.orgid='2147' ) aa on
mtd.id=aa.MONITORMETHODID where item.id='10100' order by mtd.creator
select item.id,item.name2,mt.id,mt.name,mt.itemtype,mtd.id,mtd.name
,mtd.methodsource,aa.iscertified,aa.certifiedname,aa.personnum,aa.id,aa.ORGID,
mtd.apptype,mtd.creator from itemtype
item left join monitoritems mt on item.id=mt.itemtype left join
monitormethods mtd on mt.id=mtd.itemtype left join (select mtf.id,mtf.MONITORMETHODID,
mtf.iscertified,mtf.certifiedname,mtf.personnum,mtf.ORGID from monitoritemsinfo mtf
where mtf.creator='hebeidata' and mtf.orgid='2147' ) aa on
mtd.id=aa.MONITORMETHODID where item.id='10100' order by mtd.creator