我有兩個意見我要合併到單一視圖,例如如何在單個View中加入兩個視圖在sql中?
查看1被定義爲:
CREATE VIEW view2
AS
select DV.valueId, DV.value,E.ElementId,E.name,
ES.ElementSetGroupId,ET.entryId,ET.name as E_Name,
ET.SystemDateTime,C.compositionId,C.linkSetRef
from DataValue DV
inner join Element E
on DV.valueId=E.valueRef
inner join ElementSet ES
on E.ElementId=ES.ElementRef
inner join Entry ET
on ES.elementSetGroupId=ET.elementSetGroupRef
inner join EntrySet ESG
on ESG.entryRef=ET.entryId
inner Join Section S
on s.entrySetGroupRef=ESG.entrySetGroupId
inner join SectionSet SS
on SS.sectionRef=S.sectionId
where S.name='Appointment'
如何將它們結合起來:
CREATE VIEW view1 AS
select DV.demValueId,DV.value,DE.demElementId,DE.name,
DES.demElementSetGroupId,DR.demRecordId,DR.name as Role,
DR.demClusterSetGroupRef,L.EmailId
from DemographicsDataValue DV
inner join DemographicsElement DE
on DV.demValueId=DE.demValueRef
inner join DemographicsElementSet DES
on DE.demElementId=DES.demElementRef
inner join DemographicsRecord DR
on DR.demElementSetGroupRef=DES.demElementSetGroupId
inner join LoginDetail L
on DR.demRecordId=L.demRecordIdRef
查看2被定義成單一視圖 select * from View1 選擇* from View2
輸出成單查詢
請幫忙
列在每個視圖中是否相同?假設是這樣,使用'union' ... – sgeddes
沒有兩個視圖有不同的列 –
將它們視爲表並將它們連接到適當的字段。 –