当我们在表中仅使用主题ID时,如何从表中选择主题名称,我们正在使用另一个表主题。
<properties>
<cucumber-version>1.2.4</cucumber-version>
<junit-version>1.2.4</junit-version>
</properties>
<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>{junit-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>{junit-version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.2</version>
<configuration>
<argLine>-Duser.language=en</argLine>
<argLine>-Xmx1024m</argLine>
<argLine>-XX:MaxPermSize=256m</argLine>
<argLine>-Dfile.encoding=UTF-8</argLine>
<useFile>false</useFile>
</configuration>
</plugin>
</plugins>
</build>
如何获得Sohan,Mohan和Neha选择的主题???
我希望结果像
Table StudentMaster
--------------------------
StudentId int Unchecked
StudentName varchar(50) Checked
Subject1 int Checked
Subject2 int Checked
Subject3 int Checked
Sample Record
------------------------------------
ID Name Subject1 Subject2 Subject3
1 Mohan 1 2 4
2 Sohan 3 2 5
3 Neha 5 1 2
Table Subject
-----------------------
SubjectId int Unchecked
SubjectName varchar(150) Checked
Sample Record
-----------------
SubjectId SubjectName
1 Hindi
2 English
3 Physics
4 Chemistry
5 Maths
答案 0 :(得分:3)
试试这个:
SELECT
SM.StudentId,
SM.StudentName,
S1.SubjectName AS "Subject1",
S2.SubjectName AS "Subject2",
S3.SubjectName AS "Subject3"
FROM StudentMaster SM
LEFT JOIN Subject S1
S1.SubjectId = SM.Subject1
LEFT JOIN Subject S2
S2.SubjectId = SM.Subject2
LEFT JOIN Subject S3
S3.SubjectId = SM.Subject3
答案 1 :(得分:0)
SELECT
S.StudentId,
S.StudentName,
S1.SubjectName AS Subject1,
S2.SubjectName AS Subject2,
S3.SubjectName AS Subject3
FROM StudentMaster S
LEFT OUTER JOIN Subject S1
S1.SubjectId = S.Subject1
LEFT OUTER JOIN Subject S2
S2.SubjectId = S.Subject2
LEFT OUTER JOIN Subject S3
S3.SubjectId = S.Subject3
ORDER BY S.StudentId