Sql 以第三范式组合数据库表

Sql 以第三范式组合数据库表,sql,database,relational-database,Sql,Database,Relational Database,我有一个包含5个表的关系数据库 1. student (Name, StudentID) 2. favorite_colorID (StudentID, ColorID) 3. favorite_collegeID (StudentID, CollegeID) 4. color (ColorID, Color) 5. college (CollegeID, College) 我想提出一个只打印出姓名、颜色和学院的查询 这可能是一个简单的连接问题,但我已经有一年没有做过认真的查询了(lil ru

我有一个包含5个表的关系数据库

1. student (Name, StudentID)
2. favorite_colorID (StudentID, ColorID)
3. favorite_collegeID (StudentID, CollegeID)
4. color (ColorID, Color)
5. college (CollegeID, College)
我想提出一个只打印出姓名、颜色和学院的查询


这可能是一个简单的连接问题,但我已经有一年没有做过认真的查询了(lil rusty)。

在表中按照外键操作。表学生链接到favorite_colorId和favorite_collegeID。当你以studentId为基础将这两个属性进行内部连接时,你将收到ColorId和CollegeId。一旦你有了这两个,你就可以根据桌子的颜色和颜色进行内部连接

student -> favorite_colorID -> color
student -> favorite_collegeID -> college

我不想给你sql,但是现在你知道了路径,我相信你能做到

在表格中按外键。表学生链接到favorite_colorId和favorite_collegeID。当你以studentId为基础将这两个属性进行内部连接时,你将收到ColorId和CollegeId。一旦你有了这两个,你就可以根据桌子的颜色和颜色进行内部连接

student -> favorite_colorID -> color
student -> favorite_collegeID -> college
    select s.name, c.color, co.college 
from student s inner join favorite_colorId fc on s.studentId = fc.studentId 
inner join color c on fc.colorId = c.colorId 
inner join favorite_collegeId fco on s.studentId = fco.studentId 
inner join college co on fco.collegeId = co.collegeId

我不想给你sql,但是现在你知道了路径,我相信你能做到

在表格中按外键。表学生链接到favorite_colorId和favorite_collegeID。当你以studentId为基础将这两个属性进行内部连接时,你将收到ColorId和CollegeId。一旦你有了这两个,你就可以根据桌子的颜色和颜色进行内部连接

student -> favorite_colorID -> color
student -> favorite_collegeID -> college
    select s.name, c.color, co.college 
from student s inner join favorite_colorId fc on s.studentId = fc.studentId 
inner join color c on fc.colorId = c.colorId 
inner join favorite_collegeId fco on s.studentId = fco.studentId 
inner join college co on fco.collegeId = co.collegeId

我不想给你sql,但是现在你知道了路径,我相信你能做到

在表格中按外键。表学生链接到favorite_colorId和favorite_collegeID。当你以studentId为基础将这两个属性进行内部连接时,你将收到ColorId和CollegeId。一旦你有了这两个,你就可以根据桌子的颜色和颜色进行内部连接

student -> favorite_colorID -> color
student -> favorite_collegeID -> college
    select s.name, c.color, co.college 
from student s inner join favorite_colorId fc on s.studentId = fc.studentId 
inner join color c on fc.colorId = c.colorId 
inner join favorite_collegeId fco on s.studentId = fco.studentId 
inner join college co on fco.collegeId = co.collegeId

我不想给你sql,但是现在你知道了路径,我相信你能做到

所有的学生都有自己喜欢的颜色吗?如果不知道,则如果要返回已知颜色或颜色但不同时知道两者的记录,则需要使用外部联接。那些没有定义颜色或学院的学生呢?你想退货吗?同样,如果是这样的话,左外连接。对于这个例子,它们都有一个最喜欢的颜色和一个学院。这是一个内部连接数据库表的(半)简单示例。所有学生都有自己喜欢的颜色或颜色吗?如果不知道,则如果要返回已知颜色或颜色但不同时知道两者的记录,则需要使用外部联接。那些没有定义颜色或学院的学生呢?你想退货吗?同样,如果是这样的话,左外连接。对于这个例子,它们都有一个最喜欢的颜色和一个学院。这是一个内部连接数据库表的(半)简单示例。所有学生都有自己喜欢的颜色或颜色吗?如果不知道,则如果要返回已知颜色或颜色但不同时知道两者的记录,则需要使用外部联接。那些没有定义颜色或学院的学生呢?你想退货吗?同样,如果是这样的话,左外连接。对于这个例子,它们都有一个最喜欢的颜色和一个学院。这是一个内部连接数据库表的(半)简单示例。所有学生都有自己喜欢的颜色或颜色吗?如果不知道,则如果要返回已知颜色或颜色但不同时知道两者的记录,则需要使用外部联接。那些没有定义颜色或学院的学生呢?你想退货吗?同样,如果是这样的话,左外连接。对于这个例子,它们都有一个最喜欢的颜色和一个学院。这是一个内部连接数据库表的(半)简单示例。
    select s.name, c.color, co.college 
from student s inner join favorite_colorId fc on s.studentId = fc.studentId 
inner join color c on fc.colorId = c.colorId 
inner join favorite_collegeId fco on s.studentId = fco.studentId 
inner join college co on fco.collegeId = co.collegeId