1

请任何人帮助我解决这个环境:MS Access 2010,Windows 7 我想将两个查询
1)特定程序中的活跃人员(她 9)
2)与他们的最后一次测试联系起来

添加 1)

SELECT per.perNachname,
       per.perMitgliedsnummer,
       prm.prmID,
       tei.teiangIDRef,
       tei.teiperIDRef,
       prm.prmpdaIDRef,
       prm.prmdegIDRef
FROM ( tblPersonen AS per
       RIGHT JOIN tblTeilnahmen AS tei 
       ON 
       (per.perMitgliedsnummer=tei.teiperIDRef 
        AND  tei.teiangIDRef = 9)
      )
       LEFT JOIN 
       tblPromotionTest  AS prm
       ON 
       prm.prmperIDRef=per.perMitgliedsnummer

这行得通,但我看到很多行而不是这个,我希望每个人只看到最后一个测试的行,或者如果这个人没有通过任何测试,右侧什么都没有。>>> 这个想法类似于 tblPERSON LEFT JOIN tblTEST <<<

添加 2)

SELECT p.prmperIDRef,
       p.prmID,
       p.prmpdaIDRef,
       p.prmdegIDRef
FROM tblPromotionTest AS p 
     LEFT JOIN tblPromotionTest AS p2 
     ON (p.prmID < p2.prmID) 
     AND (p.prmperIDRef=p2.prmperIDRef)
     WHERE p2.prmperIDRef Is Null

提前感谢您的支持亲切问候伯恩哈德

我发现了以下规避:

SELECT per.perNachname, per.perVorname, per.perMitgliedsnummer, prm.prmID, prm.prmpdaIDRef, prm.prmdegIDRef

FROM tblPersonen AS per LEFT JOIN tblPromotionTest AS prm ON per.perMitgliedsnummer = prm.prmperIDRef

WHERE prm.prmID IN (
SELECT p.prmID
FROM tblPromotionTest AS p LEFT JOIN tblPromotionTest AS p2 ON (p.prmID < p2.prmID) AND (p.prmperIDRef=p2.prmperIDRef)
WHERE p2.prmperIDRef Is Null)

AND per.perMitgliedsnummer IN 

(
SELECT tei.teiperIDRef
FROM tblPersonen AS per INNER JOIN tblTeilnahmen AS tei ON per.perMitgliedsnummer = tei.teiperIDRef
WHERE (((tei.teiangIDRef)=9))
)

UNION SELECT per.perNachname, per.perVorname, per.perMitgliedsnummer,  prm.prmID, prm.prmpdaIDRef, prm.prmdegIDRef
FROM tblPersonen AS per LEFT JOIN tblPromotionTest AS prm ON per.perMitgliedsnummer = prm.prmperIDRef
WHERE prm.prmID Is Null and per.perMitgliedsnummer IN (SELECT tei.teiperIDRef
FROM tblTeilnahmen as tei
WHERE tei.teiangIDRef=9);
4

0 回答 0