由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - SQL问题求救!!
相关主题
请教一个SQL问题stored procedure running 很慢的问题
求助SQL高手,这个join怎么做比较好Does MS SQL 7 support SQL3 Datatype?
keep group of values of SQL procedure in one tablea simple question about T-SQL
database design issueProblem when using SQL " Insert...." to AutoNumber.
mySQL 问题 (转载)Questions about building a database(Maybe ACCESS?)
generate unique integer ID from columns in SQL table (转载the most stupid question
How to handle inserting value to Identity column in sql server 2005请大侠帮帮忙!SQL server error问题。
My SQL question: auto incrementHelp on Sql server huge table performance
相关话题的讨论汇总
话题: value1话题: value2话题: result话题: insert话题: sequence
进入Database版参与讨论
1 (共1页)
l*****y
发帖数: 8
1
本人有简单问题求教
已通过查询获得若干个结果,现必须将这些结果insert
到另一个表,say: result(number,value1,value2)
现在问题是:
只有value1 和value2是已知道的(即前面的结果)。可是
number 是一个primary key,表示序号如1,2,3,4,5,....
请问怎么样写insert into result(number,value1,value2)..???
我的意思是有100个value1,value组成的tuple.如何得到
table result such as
number value1 value 2
1 x1 y1
2 x2 y2
.....................
100 x100 y100
我尝试用

insert into result(number,value1,value2)
(
select number,A.value1,A,value2
from A
)
但是如何累加num
s*****g
发帖数: 17
2
In the result table, you may need an identity.
CREATE TABLE RESULT
(id int identity(1,1) not null,
value1 datatype,
value2 datatype
)
Then you can insert the values of value1 and value21.
INSERT INTO RESULT(value1, value2)
SELECT value1,value2
FROM A
Hope that it works.

【在 l*****y 的大作中提到】
: 本人有简单问题求教
: 已通过查询获得若干个结果,现必须将这些结果insert
: 到另一个表,say: result(number,value1,value2)
: 现在问题是:
: 只有value1 和value2是已知道的(即前面的结果)。可是
: number 是一个primary key,表示序号如1,2,3,4,5,....
: 请问怎么样写insert into result(number,value1,value2)..???
: 我的意思是有100个value1,value组成的tuple.如何得到
: table result such as
: number value1 value 2

s*****g
发帖数: 17
3
BTW, in the function identity(1,1), you have the id++ everytime you
have a new record. So you don't have to insert values for this attribute.

【在 s*****g 的大作中提到】
: In the result table, you may need an identity.
: CREATE TABLE RESULT
: (id int identity(1,1) not null,
: value1 datatype,
: value2 datatype
: )
: Then you can insert the values of value1 and value21.
: INSERT INTO RESULT(value1, value2)
: SELECT value1,value2
: FROM A

p****s
发帖数: 3184
4

In Oracle, it is quite easy to achieve this by using SEQUENCE.
E.g.,
CREATE SEQUENCE my_sequence
INCREMENT BY 1
START WITH 1
NOMAXVALUE;
INSERT INTO result(number,value1,value2)
select my_sequence.nextval, A.value1,A,value2
from a;
DROP SEQUENCE my_sequence.
In DB2, you must use user-defined function with scratchpad (check
Chamberline's book for coding examples) to achieve the same effects.

【在 l*****y 的大作中提到】
: 本人有简单问题求教
: 已通过查询获得若干个结果,现必须将这些结果insert
: 到另一个表,say: result(number,value1,value2)
: 现在问题是:
: 只有value1 和value2是已知道的(即前面的结果)。可是
: number 是一个primary key,表示序号如1,2,3,4,5,....
: 请问怎么样写insert into result(number,value1,value2)..???
: 我的意思是有100个value1,value组成的tuple.如何得到
: table result such as
: number value1 value 2

1 (共1页)
进入Database版参与讨论
相关主题
Help on Sql server huge table performancemySQL 问题 (转载)
Oracle Group and Index questiongenerate unique integer ID from columns in SQL table (转载
MS T-SQL 问题How to handle inserting value to Identity column in sql server 2005
Oracle到sql server的migration问题兼3个openingsMy SQL question: auto increment
请教一个SQL问题stored procedure running 很慢的问题
求助SQL高手,这个join怎么做比较好Does MS SQL 7 support SQL3 Datatype?
keep group of values of SQL procedure in one tablea simple question about T-SQL
database design issueProblem when using SQL " Insert...." to AutoNumber.
相关话题的讨论汇总
话题: value1话题: value2话题: result话题: insert话题: sequence