写出sql语句实现查询,“数据库”课程成绩大于80的学生姓名,自定义表结构,并对语法树进行代数优化
时间: 2024-05-10 08:17:39 浏览: 113
自定义表结构如下:
```
CREATE TABLE Student (
id INT PRIMARY KEY,
name VARCHAR(20)
);
CREATE TABLE Course (
id INT PRIMARY KEY,
name VARCHAR(20)
);
CREATE TABLE Score (
student_id INT,
course_id INT,
score INT,
PRIMARY KEY (student_id, course_id),
FOREIGN KEY (student_id) REFERENCES Student(id),
FOREIGN KEY (course_id) REFERENCES Course(id)
);
```
查询语句如下:
```
SELECT Student.name
FROM Student
JOIN Score ON Student.id = Score.student_id
WHERE Score.score > 80;
```
代数优化后的语法树如下:
```
PROJECT(name)
|
JOIN(Student.id = Score.student_id)
| |
| SELECT(Score.score > 80)
| |
| SCORE
|
STUDENT
```
阅读全文