Sqlite 从切除表创建新表
编写一个查询,输出另一个版本的先决条件表,其中课程由标题而不是ID表示。在生成的表中,将列“课程id”和“预申请id”分别重命名为“课程”和“先决条件”。不使用联接或产品编写此查询 这是我的桌子 表名:课程Sqlite 从切除表创建新表,sqlite,Sqlite,编写一个查询,输出另一个版本的先决条件表,其中课程由标题而不是ID表示。在生成的表中,将列“课程id”和“预申请id”分别重命名为“课程”和“先决条件”。不使用联接或产品编写此查询 这是我的桌子 表名:课程 表名:prereq 我的代码 //只是给我介绍一下所有的预选课 select title,( select title from course as C where course_id = ( select prereq_id from prereq as P
表名:prereq 我的代码 //只是给我介绍一下所有的预选课
select title,(
select title
from course as C
where course_id = (
select prereq_id
from prereq as P
where C.course_id = P.prereq_id)) as prereq
from course as C
where course_id = (
select course_id
from prereq as P
where C.course_id = P.course_id)
//这是在使用产品
select c.title, (
select title
from course as q
where q.course_id = p.prereq_id) as title2
from course as c, prereq as p
where c.course_id = p.course_id
没有连接是最糟糕的选择,但我想这是家庭作业,所以:
select
(select title from course where course_id = p.course_id) as course,
(select title from course where course_id = p.prereq_id) as prerequisite
from prereq as p
每个子查询从课程
中获取标题请参阅。
结果:
select c.title, (
select title
from course as q
where q.course_id = p.prereq_id) as title2
from course as c, prereq as p
where c.course_id = p.course_id
select
(select title from course where course_id = p.course_id) as course,
(select title from course where course_id = p.prereq_id) as prerequisite
from prereq as p
| course | prerequisite |
| ------------------------- | -------------------------- |
| Genetics | Intro. to Biology |
| Computational Biology | Intro. to Biology |
| Game Design | Intro. to Computer Science |
| Robotics | Intro. to Computer Science |
| Image Processing | Intro. to Computer Science |
| Database System Concepts | Intro. to Computer Science |
| Intro. to Digital Systems | Physical Principles |