2

我想创建一个查询,从下表中选择列 PlayerName 、 PlayerNumber 、 Location 、 PartnerName 、 PartnerNumber 、 Location :

  • 玩家(列:Id、PlayerName、PlayerNumber、LocationId)
  • 合作伙伴(列:Id、PartnerName、PartnerNumber、LocationId)
  • 位置(列:ID、位置)

但我不知道该怎么做。有没有人有任何想法?

4

5 回答 5

2

考虑注册表后找到更新的查询。

SELECT players.playername, 
       player.playernumber, 
       L1.location, 
       partners.partnername, 
       partners.partnernumber, 
       L2.location 
FROM   registration R 
       INNER JOIN players 
               ON players.id = R.playerid 
       INNER JOIN partners 
               ON partners.id = R.partnerid 
       INNER JOIN locations L1 
               ON players.locationid = L1.id 
       INNER JOIN locations L2 
               ON partners.locationid = L2.id 
于 2012-06-27T09:47:10.357 回答
2

简单直接的方法

select PL.PlayerName , PL.PlayerNumber, L.Location, PT.PartnerName, PT.PartnerNumber
from  Players PL, Location L, Patners PT
where L.id = PL.LocationId and L.id = P.LocationId

这也可以使用 UNION 来完成,但对此不太确定

于 2012-06-27T09:44:29.720 回答
1

试试这个..我不确定

select pl.Id,pl.PlayerName,pl.PlayerNumber,pa.ID,pa.PartnerName,pa.PartnerNumber,l.Location 
from Players as  pl,Partners as pa ,Location as l 
where pl.LocationId = pa.LocationId and l.LocationId = pl.LocationId
and pa.LocationId = l.LocationId
AND l.LocationId = <some id>
于 2012-06-27T09:44:44.697 回答
0
select
  PlayerName,
  PlayerNumber,
  Location,
  PartnerName,
  PartnerNumber
from players
  left join locations
    on locations.id = players.LocationId
  left join partners
    on partners.LocationId = locations.id
于 2012-06-27T10:16:25.103 回答
0
Select PlayerName , PlayerNumber, Location, PartnerName, PartnerNumber
from Players pl
inner join Partners pa on pl.LocationId=pa.LocationId
inner join Location L on L.id=pa.LocationId
where Location = 'String to search for'
于 2012-06-27T09:39:40.097 回答