Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sqlite 从切除表创建新表_Sqlite - Fatal编程技术网

Sqlite 从切除表创建新表

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

编写一个查询,输出另一个版本的先决条件表,其中课程由标题而不是ID表示。在生成的表中,将列“课程id”和“预申请id”分别重命名为“课程”和“先决条件”。不使用联接或产品编写此查询

这是我的桌子

表名:课程
表名: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        |