我的 mysql 数据库中有 3 个表:student, progress and subject
. 当我尝试选择数据时:
SELECT progress.id, progress.mark, subject.pname FROM progress, subject WHERE progress.id_student = 1;
我得到下表:
id mark pname
1 5 Math
1 5 Physics
表进度我只有一个条目:
id mark id_student id_subject
1 5 1 1
我怎样才能得到学生的进步student_id
?
CREATE DATABASE students;
USE students;
CREATE TABLE student (
id int NOT NULL AUTO_INCREMENT,
name varchar(100) NOT NULL,
address varchar(60) NOT NULL,
byear int NOT NULL,
eyear int NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE subject (
id int NOT NULL AUTO_INCREMENT,
pname varchar(20) NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE progress (
id int NOT NULL AUTO_INCREMENT,
mark int NOT NULL,
id_student int NOT NULL,
id_subject int NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (id) REFERENCES student (id),
FOREIGN KEY (id) REFERENCES subject (id)
);