-1

我有 2 个表 tbl_Party 和 Link_Party

tbl_Party
Columns
PartyId - uniquekey,
PartyNAme,
sk_party,

链接表

link_party
Coulmns
PartyId_a,
PartyId_b,
linktype

现在派对表将有不同的派对ID。派对表中的一些各方可以在链接表中相互链接现在,我需要编写一个查询,例如

select 
  partyid_a,
  sk_party,
  partyid_b,
  sk_party 
from 
  party, 
  link_party
4

2 回答 2

0

如果我正确理解了您的表结构,则如下所示:

SELECT      L.PartyId_a,
            PA.sk_party,
            L.PartyId_b,
            PB.sk_party
FROM        link_party L
INNER JOIN  tbl_Party PA ON L.PartyId_a = PA.PartyId
INNER JOIN  tbl_Party PB ON L.PartyId_b = PB.PartyId
于 2013-08-02T10:18:15.690 回答
0

参考这个你会得到一些想法

SELECT
  a.partyid    AS partyid_a,
  a.sk_party     AS sk_party_a, 
  b.partyid    AS partyid_b,
  b.sk_party     AS sk_party_b, 
FROM
  party              AS a
INNER JOIN
  link_party            AS lp
    ON lp.partyid_a = a.partyid
INNER JOIN
  party              AS b
  ON lp.partyid_b = b.partyid
于 2013-08-02T10:22:37.923 回答