Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 在sqlserver中连接3个非常复杂的表_Sql Server_Join_Inner Join - Fatal编程技术网

Sql server 在sqlserver中连接3个非常复杂的表

Sql server 在sqlserver中连接3个非常复杂的表,sql-server,join,inner-join,Sql Server,Join,Inner Join,我想去 i have 3 tables (employee,structure,District) 1_employee table contains empid,workid and actuallwork fks to structid 2_ structure table contains structid , districtId fk to district 3_District table contains districtid , districtname ,A

我想去

 i have 3 tables (employee,structure,District)

 1_employee table contains  empid,workid  and actuallwork  fks to structid 
 2_ structure table contains structid , districtId fk to district
 3_District table contains districtid , districtname

,ActualWork(外键actulalwork中的disitrict名称)

如果为每个事件指定了不同的别名,则可以在查询中多次使用同一个表。结构和地区列出两次,第一次作为工作/地区,第二次作为实际工作/实际严格。这就是在处理对同一表的多个引用时如何区分列的来源

empid  ,  work 
select employee.empid,
       district.districtname,
       actualdistrict.districtname acturaldistrictname
  from employee
    inner join structure work
       on employee.workid = work.structid
    inner join district
       on work.districtfk = district.districtid
    inner join structure actualwork
       on employee.actuallworkfk = actualwork.structid
    inner join district actualdistrict
       on actualwork.districtfk = actualdistrict.districtid