編寫查詢以顯示由同一位醫生治療的不同患者對。
下表是存在的:根據連接中的某些條件顯示對的查詢
doctor:
d_id
d_name
patient:
p_id
p_name
treatment:
d_id
p_id
disease
medicine
查詢:
Select p1.p_name, p2.p_name
from patient p1, patient p2, treatment t1, treatment t2
where t1.d_id=t2.d_id
AND t1.p_id<>t2.p_id
AND t1.p_id=p2.p_id
AND t2.p_id=p1.p_id;
您能否提供一個更好的/替代查詢(甲骨文的風格),消除了重複對[像(P1,P6)和( P6,P1)?
明顯的對稱性破壞條件是「p1.p_id
wildplasser
2012-01-08 11:12:36
任何其他方法....?另外,@Andomar,這種情況的起源是什麼。看起來更像是一種舌尖的解決方案......拼湊而成。 – 2012-01-08 11:44:59