在表格中插入额外的行

时间:2013-11-15 08:44:27

标签: sql ms-access

我想为每个存在的零件编号在表格中添加额外的2行。目前我有这样的事情:

+-------------+-----------+---------------+
| item_number | operation | resource_code |
+-------------+-----------+---------------+
| abc         |        10 | kit           |
| abc         |        20 | build         |
| abc         |        30 | test          |
+-------------+-----------+---------------+

表格中有数百个这样的项目设置。我想根据每个部件号向表中添加2行额外的记录。所以一旦添加了这些,我的数据集将如下所示:

+-------------+-----------+---------------+
| item_number | operation | resource_code |
+-------------+-----------+---------------+
| abc         | 10        | kit           |
| abc         | 20        | build         |
| abc         | 30        | test          |
| abc         | NULL      | NULL          |
| abc         | NULL      | NULL          |
+-------------+-----------+---------------+

我希望这些新记录暂时为空,稍后再添加。

我正在使用access并查找sql​​以将这些新记录添加到表中。

1 个答案:

答案 0 :(得分:2)

尝试使用此尺寸:

INSERT INTO my_table
SELECT item_number, NULL AS operation, NULL AS resource_code 
FROM my_table 
GROUP BY item_number
UNION ALL
SELECT item_number, NULL AS operation, NULL AS resource_code 
FROM my_table 
GROUP BY item_number