如何使用其他数据从另一个表中插入表中? [英] How Do I Insert Into A Table From Another Table With Some Additional Data?
问题描述
亲爱的大家,
我有一个问题,我不知道如何从另一个表中插入一个表,其中包含一些额外的数据:
Table Student
ID |姓名
01 |吉米
02 |汤姆
....(很多数据).....
表结果
ID |名称|课程|结果
01 | 01 |数学| A +
02 | 02 |点亮| C
...(很多数据).....
表课程
ID | CourseName | Price
数学|数学| 15 $
点亮|文献| 20 $
......(很多数据).......
我想加入结果像这样,我知道'凯特'学生必须增加10门课程:
Dear everyone,
I have the issue that i don't know how to insert into a table from another table with some additional data like this:
Table Student
ID| Name
01| Jimmy
02| Tom
....( a lot data).....
Table Result
ID|Name|Course|Result
01|01 |Math | A+
02|02 |Lit | C
...( a lot data).....
Table Courses
ID |CourseName |Price
Math|Mathematics | 15$
Lit |Literature | 20$
......(a lot data).......
I want to add into Result like this,and i knew the 'Kate' student must be added 10 courses more:
insert into result(ID, Name,Course) select * from Course with ID=10000 and name='Kate'
但我知道在SQl中没有这样的方式。
无论如何我们可以使用一些变量从另一个表中插入表格而不使用函数和存储吗?
我正在使用sql 2005.
真的不知道。
请给我你的手或者只是一点点提示!
提前感谢。
此致。
Toki。
But i know there is no way like that in SQl.
Is there anyway so that we can insert into table from another table with some variables, without using function and store?
I am using sql 2005.
Really have no idea.
Please give me ur hands or just a little of hints!
Thank in advance.
Sincerely.
Toki.
点亮|文献| 20
Lit |Literature | 20
......(很多数据).......
我想像这样添加到Result中,我知道'Kate'学生必须再添加10个课程:
......(a lot data).......
I want to add into Result like this,and i knew the 'Kate' student must be added 10 courses more:
insert into result(ID, Name,Course) select * from Course with ID=10000 and name='Kate'
但是我知道在SQl中没有这样的方法。
无论如何,我们可以使用一些变量从另一个表中插入表,而不使用函数和存储?
我使用的是sql 2005.
真的不知道。
请给我你的手或只是一些提示!
提前感谢。
此致。
Toki。
But i know there is no way like that in SQl.
Is there anyway so that we can insert into table from another table with some variables, without using function and store?
I am using sql 2005.
Really have no idea.
Please give me ur hands or just a little of hints!
Thank in advance.
Sincerely.
Toki.
您可以尝试使用存储过程来实现此逻辑。
但是,如果要添加其他记录,则如果不编写更多的插入语句,将无法实现。
You could try and achieve this logic by using a stored procedure.
However, if you want to add additional records, it will not be possible without writing more insert statements.
这篇关于如何使用其他数据从另一个表中插入表中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!