-2

我有这些桌子

Person
ID_PRS   Name
------   -----
1        John
2        Brian
3        Mike

Con_PRS_Fonc
    ID_PRS  ID_FONCT  
    -----   -------
     1       17
     1       18
     3       17

   Fonction
       ID_FONCT   LABEL  ID_CATEG  ID_MET ID_ANA
       -------    -----  --------  ------ ------
         17       Boss      1        56     78
         18       Junior    1        45     56

Category
 ID_CATEG  LABEL
 --------  -----
    1      Cleaning
    2      Wahsing

MEtir
 ID_MET   LABEL
 ------   -----
  56       Go
  45       Come

Analys
 ID_ANA  LABEL
 ------  -----
  78     Think
  56     Drink

我怎样才能得到:

ID_PRS  NOM  ID_FONCT   LABEL_FONCT  ID_CATEG  LAB_CAT   ID_MET   LAB_MET   ID_AN   LAB_ANA
------  ---- --------   -----------  --------  -------    ------   -------   -----   -------
   1    John  17         Boss           1      Cleaning   56        GO        56     Think

我知道只有我可以加入表人与表 Con_PRS_Fonc,但我怎样才能加入其他人?

SELECT * FROM PERSON
LEFT JOIN Con_PRS_Fonc ON PERSON.ID_PRS = Con_PRS_Fonc .ID_PRS 

提前谢谢你,史蒂夫

4

2 回答 2

0

像这样的东西:

SELECT * FROM person as P
INNER JOIN Con_PRS_Fonc AS CPF ON P.ID_PRS = CPF.ID_PRS 
INNER JOIN FONCTION AS FON ON FON.ID_FONCT = CPF.ID_FONCT
INNER JOIN CATEGORY AS C ON FON.ID_CATEG = C.ID_CATEG
INNER JOIN MEtir AS MEt ON Fon.ID_MET = MEt.ID_MET
INNER JOIN Analys AS ANA ON Fonc.ID_ANA = ANA.ID_ANNA

我无法确认它 100% 正确,但只是加入关系表:)

于 2012-04-18T10:08:47.330 回答
0

这应该让你得到你想要的:

    SELECT 
Person.ID_PRS, 
Person.Name, 
Fonction.ID_FONCT, 
Fonction.LABEL AS LABEL_FONCT,
Fonction.ID_CATEG,
Category.LABEL AS LAB_CAT,
MEtir.ID_MET,
MEtirLABEL AS LAB_MET, 
Analys.ID_ANA,
Analys.LABEL AS LAB_ANS
FROM PERSON
INNER JOIN Con_Prs_Fonc ON Person.ID_PRS = Con_Prs_Fonc.ID_PRS
INNER JOIN Fonction ON Fonction.ID_FONCT = Con_Prs_Fonc.ID_FONCT
INNER JOIN Category ON Category.ID_CATEG = Fonction.ID_CATEG
INNER JOIN MEtir ON MEtir.ID_MET = Fonction.ID_MET
INNER JOIN Analys ON Analys.ID_ANA = Fonction.ID_ANA
于 2012-04-18T10:19:22.710 回答