2

2つのテーブルがあります。従業員と資格。

従業員

Emp_id   Name   Qualification1   Qualification2    Qualification3
10001   xxxxxx         1              3                5
10002   yyyyyy         3              2                       
.......
......
.....

資格

Qual_ID   Qual_name
    1      B.Tech
    2      MCA
    3      M.Tech

結合クエリを使用して次の出力を取得するにはどうすればよいですか?

Emp_ID   Name    Qual1   Qual2   Qual3
10001   xxxxxxx  B.Tech   MCA     pppp
10002   yyyyyyy  B.Tech   
......
.....
.....
4

3 に答える 3

5

これを試して

Select E.Emp_ID,E.Name,Q1.Qual_Name,Q2.Qual_Name, Q3.Qual_Name
From 
    Employees AS E
    INNER JOIN Qualifications As Q1 ON E.Qualification1=Q1.Qual_ID
    INNER JOIN Qualifications As Q2 ON E.Qualification2=Q2.Qual_ID
    INNER JOIN Qualifications As Q3 ON E.Qualification3=Q3.Qual_ID
于 2012-06-25T10:06:37.070 に答える
3
SELECT e.emp_id, 
       e.name, 
       q1.qual_name, 
       q2.qual_name, 
       q3.qual_name, 
FROM   employee e 
       INNER JOIN qualifications q1 
               ON e.qualification1 = q1.qual_id 
       INNER JOIN qualifications q2 
               ON e.qualification2 = q2.qual_id 
       INNER JOIN qualifications q3 
               ON e.qualification3 = q2.qual_id 
于 2012-06-25T10:06:57.803 に答える
0

これを試して:

SQLフィドル

Select
    Emp_id, Name, 
    (Select Qual_name from Qualifications where Qualifications.Qual_ID = Employee.Qualification1) as Qual1,
    (Select Qual_name from Qualifications where Qualifications.Qual_ID = Employee.Qualification2) as Qual2,
    (Select Qual_name from Qualifications where Qualifications.Qual_ID = Employee.Qualification3) as Qual3
From Employee
于 2012-06-25T10:04:17.563 に答える