1

在以下查询中,我尝试为 rs1 和 rs2 创建 2 个内部连接,但是在 sql server 中,我只能选择 rr1.ResourceId=rs2.Id 但我无法制作 rr1.ResourceId=rs1.Id

你能解释一下我应该怎么做吗?

select r.OwningTerritoryId ,rs1.ISRC , rs2.ISRC 
from Resource rs1 , Resource rs2
    inner join ReleaseResource rr1 
       on rr1.ResourceId=rs2.Id

谢谢。

4

2 回答 2

1

试试这样......

select r.OwningTerritoryId ,rs1.ISRC , rs2.ISRC from Resource rs1 
inner join ReleaseResource rr1 on rr1.ResourceId=rs2.Id
于 2013-06-10T14:38:00.943 回答
1

您可以根据需要创建任意数量的内部连接...

select r.OwningTerritoryId ,rs1.ISRC , rs2.ISRC 
from Resource rs1
    inner join ReleaseResource rr2 
       on rr2.ResourceId=rs1.Id
    inner join ReleaseResource rr2
       on rr3.ResourceId=rs1.Id
    inner join ReleaseResource rr3
       on rr4.ResourceId=rs1.Id
    inner join ReleaseResource rr4
       on rr5.ResourceId=rs1.Id

虽然,[通常],您这样做的原因要求每个连接都有不同的连接条件。

如果您希望连接在一对中的每个表之间,然后在对之间,然后尝试:

select r.OwningTerritoryId ,rs1.ISRC , rs2.ISRC 
   from (Resource r1 join ReleaseResource rr1 
               On rr1.ResourceId = r1.Id)
      join (Resource r2 join ReleaseResource rr2 
               On rr2.ResourceId = r2.Id)
         On r2.id = r1.id   -- Here put condition for this join between the pairs 
于 2013-06-10T14:40:47.100 回答