Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/87.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
Sql 使用select插入到表中_Sql_Sql Insert - Fatal编程技术网

Sql 使用select插入到表中

Sql 使用select插入到表中,sql,sql-insert,Sql,Sql Insert,我有两个具有以下架构的表: student(id,name,dept_name, tot_cred) instructor(id,name,dept_name,salary) 问题是: 插入tot_cred属性大于100的每个学生作为 同一系的讲师,薪水10000美元 我尝试了这个查询,但我不知道如何设置学生10000美元的工资: insert into instructor (id,name,dept_name,salary) select id,name,dept_name

我有两个具有以下架构的表:

student(id,name,dept_name, tot_cred)
instructor(id,name,dept_name,salary)
问题是:

插入tot_cred属性大于100的每个学生作为 同一系的讲师,薪水10000美元


我尝试了这个查询,但我不知道如何设置学生10000美元的工资:

insert into instructor (id,name,dept_name,salary) 
  select id,name,dept_name 
    from student 
   where tot_cred > 100

只需选择常量值。就我个人而言,我会在
select
中添加一个别名,以记录该常量将用作
salary
,尽管这不是必需的。对于如何创建别名,不同的数据库可能有不同的规则,而您还没有告诉我们您使用的是哪个数据库,所以我在猜测语法

insert into instructor (id,name,dept_name,salary) 
  select id,name,dept_name,10000 as salary
    from student 
   where tot_cred > 100
插入到讲师中 (id), 名称 部门名称, 薪金) 选择id, 名称 部门名称, 10000美元作为薪水 来自学生
其中tot_cred>=100

我想这是一个家庭作业问题。我们很乐意帮助学生,但我们没有为你做家庭作业的习惯。让我们看看你试过什么。告诉我们您看到了什么(错误?如果是,什么错误?错误结果?如果是,预期结果和实际结果是什么)。告诉我们您不确定的具体位置。您还为4个不同的数据库——MySQL、Oracle、SQL Server和PostgreSQL——标记了这个问题。每种语言都使用不同的SQL方言,因此您可能需要对每种语言使用不同的语法。您实际使用的是哪一个?我尝试了这个查询,但我不知道如何设置学生$10000的工资:插入到讲师(id、姓名、部门名称、工资)中,从tot\u cred>100的学生中选择id、姓名、部门名称