Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/83.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 如何按顺序更新丢失的记录_Sql_Sql Insert_Recursive Query_Monetdb - Fatal编程技术网

Sql 如何按顺序更新丢失的记录

Sql 如何按顺序更新丢失的记录,sql,sql-insert,recursive-query,monetdb,Sql,Sql Insert,Recursive Query,Monetdb,我在一个序列中丢失了记录,我当前的输出如下所示 | 1882 | 25548860 | 4 | 30 | null | null | | 1882 | 25548861 | 4 | 30 | null | null | | 1882 | 25548882 | 4 | 30

我在一个序列中丢失了记录,我当前的输出如下所示

|       1882 |   25548860 |         4 | 30                  | null      |       null |
|       1882 |   25548861 |         4 | 30                  | null      |       null |
|       1882 |   25548882 |         4 | 30                  | null      |       null |
|       1882 |   25548883 |         4 | 30                  | null      |       null |
|       1882 |   25548884 |         4 | 30                  | null      |       null |
|       1882 |   25548885 |         4 | 30                  | null      |       null |
                         missing records in between until 2122
|       2122 |   25548860 |         4 | 30                  | null      |       null |
|       2122 |   25548861 |         4 | 30                  | null      |       null |
|       2122 |   25548882 |         4 | 30                  | null      |       null |
|       2122 |   25548883 |         4 | 30                  | null      |       null |
|       2122 |   25548884 |         4 | 30                  | null      |       null |
|       2122 |   25548885 |         4 | 30                  | null      |       null |
我希望我的输出为以下格式。建议我一个sql查询,它将在1883年到2121年间更新monetdb中的记录

|       1882 |   25548860 |         4 | 30                  | null      |       null |
|       1882 |   25548861 |         4 | 30                  | null      |       null |
|       1882 |   25548882 |         4 | 30                  | null      |       null |
|       1882 |   25548883 |         4 | 30                  | null      |       null |
|       1882 |   25548884 |         4 | 30                  | null      |       null |
|       1882 |   25548885 |         4 | 30                  | null      |       null |

|       1883 |   25548860 |         4 | 30                  | null      |       null |
|       1883 |   25548861 |         4 | 30                  | null      |       null |
|       1883 |   25548882 |         4 | 30                  | null      |       null |
|       1883 |   25548883 |         4 | 30                  | null      |       null |
|       1883 |   25548884 |         4 | 30                  | null      |       null |
|       1883 |   25548885 |         4 | 30                  | null      |       null |
     ........   ..........
     ........   ..........
|       2122 |   25548860 |         4 | 30                  | null      |       null |
|       2122 |   25548861 |         4 | 30                  | null      |       null |
|       2122 |   25548882 |         4 | 30                  | null      |       null |
|       2122 |   25548883 |         4 | 30                  | null      |       null |
|       2122 |   25548884 |         4 | 30                  | null      |       null |
|       2122 |   25548885 |         4 | 30                  | null      |       null |

如果您事先知道缺少
id
s的范围,可以使用
generate_series()
。假设您的表名为
mytable
,并且具有列
(id、col1、col2、col3、col4、col5)
,则可以复制具有
id
1882的记录,以使用以下查询填补空白:

insert into mytable (id, co11, col2, col3, col4, col5)
select value, col1, col2, col3, col4, col5
from sys.generate_series(1883, 2121, 1)
cross join mytable t
where t.id = 1882

如果您事先知道缺少
id
s的范围,可以使用
generate_series()
。假设您的表名为
mytable
,并且具有列
(id、col1、col2、col3、col4、col5)
,则可以复制具有
id
1882的记录,以使用以下查询填补空白:

insert into mytable (id, co11, col2, col3, col4, col5)
select value, col1, col2, col3, col4, col5
from sys.generate_series(1883, 2121, 1)
cross join mytable t
where t.id = 1882

假设表的架构类似于:

create table mytable(id int, col1 int, col2 int, col3 int, col4 int, col5 int);
您可以用以下内容填写“缺失记录”:

但是,新记录将附加到现有记录中,因此,如果您希望按照上面显示的顺序返回这些记录,则需要以下附加顺序:

select * from mytable order by id, col1;

假设表的架构类似于:

create table mytable(id int, col1 int, col2 int, col3 int, col4 int, col5 int);
您可以用以下内容填写“缺失记录”:

但是,新记录将附加到现有记录中,因此,如果您希望按照上面显示的顺序返回这些记录,则需要以下附加顺序:

select * from mytable order by id, col1;

您想在表中实际插入额外的行,还是仅仅作为查询的结果显示这些行?能否显示您正在使用的查询?@TheImpler我想插入records@BoilermakerRV我只是使用一个基本的select语句来查询我的表,其中我缺少1883到2121条记录。该表遵循一种趋势,在第6行之后得到迭代。因此,我想按上面提到的格式插入记录。是否确实要在表中插入额外的行,或者只是作为查询的结果显示它们?您能显示您正在使用的查询吗?@TheImpler我想插入records@BoilermakerRV我只是使用一个基本的select语句来查询我的表,其中我缺少1883到2121条记录。该表遵循一种趋势,在第6行之后得到迭代。因此,我想以上面提到的所需格式插入记录。