基于其他 table 创建一个 table

create a table based on other tables

我有 4 个不同的 tables:

student: sid, name, gender 

grades: sid, grade

address: postcode, sid, distance_to_school

health_condition: sid, health_code

现在我想创建一个新的 table,其中包含我上面提到的所有列。我需要根据 sid 加入他们。我尝试单独添加列,但代码真的很长。那么还有其他方法可以完成这项任务吗?

如果要显示要创建的第五个 table 的数据,我认为使用查询更好,因此不需要第五个 table。刚刚

"SELECT * FROM student s
INNER JOIN grades g
on s.sid = g.sid
INNER JOIN address a
on s.sid = a.sid
INNER JOIN health_condition h
on s.sid = h.sid
ORDER BY sid ASC";

请使用下面的查询将为您提供准确的结果集。

SELECT t1.sid, t1.name, t1.gender , t2.grade,t3.postcode, t3.distance_to_school, 
t4.health_code AS 
student as t1 inner join grades t2 on t1.sid=t2.sid 
inner join address as t3 on t3.sid= t1.sid 
inner join health_condition as t4 on t4.sid=t1.sid 

试试这个查询

FROM student s
LEFT JOIN grades g on g.sid = s.sid
LEFT JOIN address a on a.sid = s.sid
LEFT JOIN health_condition h on h.sid = s.sid
WHERE s.sid = ;