日期:2014-05-20  浏览次数:20531 次

3表关联--SQL,帮忙看看.在线等
Select   DISTINCT   A.user_no,   A.door_key,   B.door_name "   &   _
          "   from   T_A   A   LEFT   JOIN   T_B   B "   &   _
                    "   ON   A.door_key=B.door_key   WHERE   A.user_no=1
在这样的基础上再关联一个表T_C   C,要求A.door_key在C.door_key里面,C.ID=2

请问,该怎么关联上去?

------解决方案--------------------
INNER JOIN T_C C
ON C.door_key = A.door_key AND C.ID=2
------解决方案--------------------
建个视图
------解决方案--------------------
left join

Select DISTINCT A.user_no, A.door_key, B.door_name from T_A A LEFT JOIN T_B B ON A.door_key=B.door_key left jion T_C C on A.door_key=C.door_key where A.user_no=1 and (条件)

跟一个表多次自连一样~
------解决方案--------------------
利用“设计视图”来操作,比较方便点!
------解决方案--------------------
select B.EmployeeCD, A.EmployeeName,
B.YearMonthDay , C.YearMonthDay , D.YearMonthDay , E.YearMonthDay
from dbo.mstEmployeeBasic A
left join dbkintai.dbo.T_D_AttendanceBook B on B.EmployeeCD=A.EmployeeCode
left join dbkintai.dbo.T_D_AttendanceBook C on C.EmployeeCD=A.EmployeeCode
left join dbkintai.dbo.T_D_AttendanceBook D on D.EmployeeCD=A.EmployeeCode
left join dbkintai.dbo.T_D_AttendanceBook E on E.EmployeeCD=A.EmployeeCode
where B.YearMonthDay= '2006-11-08 ' and C.YearMonthDay= '2006-11-09 '
and D.YearMonthDay= '2006-11-10 ' and E.YearMonthDay= '2006-11-11 '
这是我的 你的没有环境 建个麻烦 你参考我的