我需要为sqlite设计一个查询
最初的查询是这样的
FROM PhysicianActivity INNER JOIN
Activity ON PhysicianActivity.ActivityID = Activity.ID RIGHT OUTER JOIN
PhysicianFrequency ON PhysicianActivity.PhysicianID = PhysicianFrequency.PhysicianID AND Activity.LegalEntityID = PhysicianFrequency.LegalEntityID
知道sqlite不支持右外部连接,所以我只能使用左外部连接,但无法将此查询转换为左外部连接
有人能帮忙吗?
最佳答案
大多数人喜欢LEFT OUTER JOIN
。在大多数情况下,以下内容是等效的:
FROM PhysicianFrequency LEFT JOIN
PhysicianActivity
ON PhysicianActivity.PhysicianID = PhysicianFrequency.PhysicianID LEFT JOIN
Activity
ON PhysicianActivity.ActivityID = Activity.ID AND
Activity.LegalEntityID = PhysicianFrequency.LegalEntityID
我建议您使用表别名,以便查询更易于编写和读取:
FROM PhysicianFrequency pf LEFT JOIN
PhysicianActivity pa
ON pa.PhysicianID = pf.PhysicianID LEFT JOIN
Activity a
ON pa.ActivityID = a.ID AND
a.LegalEntityID = pf.LegalEntityID