有谁能告诉我为什么会收到此错误?
SELECT C.ClientID, C.ClientCode, C.FullName, E.FullName AS EmployeeName
FROM ClientID C, EmployeeInfo E, tmntClientTreatmentInfo T, CliniciansClients CC
JOIN CliniciansClients
ON CliniciansClients.ClientID = ClientID.ClientID
JOIN ClientID
ON ClientID.ClientID = CliniciansClients.ClientID
JOIN EmployeeInfo
ON EmployeeInfo.EmployeeID = CliniciansClients.EmployeeID
JOIN tmntClientTreatmentInfo
ON tmntClientTreatmentInfo.ClientID = ClientID.ClientID
多部分标识符" ClientID.ClientID"无法受约束。 //第6行
答案 0 :(得分:1)
Tony,有很多方法可以选择连接和许多不同类型的连接。但我建议你从做一些基本的事情开始,确保它有效,然后如果它不具备性能或带回重复数据,则开始优化连接或处理规范化/非规范化。过了一会儿,你就会掌握它。在那之前,我在Docker中快速设置了一个postgres实例,创建了你引用的表,这个查询应该可以工作:
SELECT C.ClientID, C.ClientCode, C.FullName, E.FullName AS EmployeeName
FROM ClientID C
JOIN CliniciansClients AS CC
ON CC.ClientID = C.ClientID
JOIN EmployeeInfo AS E
ON E.EmployeeID = CC.EmployeeID
JOIN tmntClientTreatmentInfo as leonardo
ON leonardo.ClientID = C.ClientID