&&将以下内容复制到.prg文件中,执行,就会发现问题
set safety off
&&创建 student表
create table student (学号 c(3),姓名 c(6))
insert into student values( "001 ", "aaaa ")
insert into student values( "002 ", "bbbb ")
insert into student values( "003 ", "cccc ")
&&创建 course表
create table course (课程号 c(3),课程名 c(6))
insert into course values( "00A ", "KC01 ")
insert into course values( "00B ", "KC02 ")
insert into course values( "00C ", "KC03 ")
&&创建 score1表
create table score1 (学号 c(3),课程号 c(3),成绩 n(3))
insert into score1 values( "001 ", "00A ",89)
insert into score1 values( "001 ", "00B ",79)
insert into score1 values( "001 ", "00C ",69)
insert into score1 values( "002 ", "00A ",83)
insert into score1 values( "002 ", "00B ",73)
insert into score1 values( "002 ", "00C ",63)
insert into score1 values( "003 ", "00A ",80)
insert into score1 values( "003 ", "00B ",70)
&&sql1,正常
SELECT * FROM score1 , course , student WHERE score1.学号 = student.学号 AND score1.课程号 = course.课程号
&&sql2
SELECT * FROM course INNER JOIN score1 INNER JOIN student ON score1.学号 = student.学号 ON score1.课程号 = course.课程号
&&sql3,姓名字段有问题
SELECT * FROM score1 INNER JOIN course INNER JOIN student ON score1.学号 = student.学号 ON score1.课程号 = course.课程号
&&sql4,课程名字段有问题
SELECT * FROM score1 INNER JOIN course INNER JOIN student ON score1.课程号 = course.课程号 ON score1.学号 = student.学号
------解决方案--------------------------------------------------------
改成这样:
&&sql2
SELECT * FROM course INNER JOIN score1 ON score1.学号 = student.学号 INNER JOIN student ON score1.课程号 = course.课程号
&&sql3
SELECT * FROM score1 INNER JOIN course ON score1.学号 = student.学号 INNER JOIN student ON score1.课程号 = course.课程号
&&sql4
SELECT * FROM score1 INNER JOIN course ON score1.课程号 = course.课程号 INNER JOIN student ON score1.学号 = student.学号