0
Use Surveydb;
create view VW_Service
As
(select A.id as 'Encounter ID'
,A.startDateTime as 'Enconter StartDateTime'
,A.endDateTime as 'Encounter EndDateTime'
,B.id as 'Service ID'
,B.startDateTime as 'Service StartDateTime'
,B.endDateTime as 'Service EndDateTime'
,C.label as 'Services Name Code Label'
,C.symbol as 'Service Name Code Symbol'
,C.system as 'Service Name Code System'
from Code C,
Encounter A,
Service B
where
a.id = b.encounterId
and c.id = b.nameCodeId)
JOIN
(select a.label as 'Service Status Code Label'
,a.symbol as 'Service Status Code Symbol'
,b.system as 'Services Status Code System'
from
Code a, Code b
Where
a.id = b.id)
我試圖創建一個包含三個表的視圖,並且還需要自行連接其中一個表。上面的腳本是視圖的單獨查詢。第一個查詢由所有三個表組成,第二個子查詢是來自代碼表的自加入查詢。我試圖加入這兩個查詢。有什麼想法嗎?使用嵌套查詢創建視圖
嗨,夫婦的問題開始。您使用的是哪種數據庫引擎,其次是從上述SQL中獲取的錯誤是什麼?謝謝! –
我想你是要求爲上述查詢optmizatrion。所以請張貼一些樣本數據和您預期的O/P結果。 –
這兩個子查詢有哪些常見字段?他們如何加入?一旦你指定我們可以寫出其餘的缺失部分。 – JNevill