请帮助使用MySQL选择要写入的数据需要一个select语句,而要创建的记录需要另一个select语句

请帮助使用MySQL选择要写入的数据需要一个select语句,而要创建的记录需要另一个select语句,mysql,sql,insert-into,Mysql,Sql,Insert Into,我有一个场景,我想在表中选择一组记录,然后根据第二个选择将新记录从第一个选择写入表中 我希望从中选择然后写入的表格是: bullets ------- id product_code catalogue_category_id bullet_text sort_sequence 对于本产品,这给出了4行,项目符号的数量可能因产品而异。结果是: 10001, , Bullet point for testing - 10001, 10001, , 2nd bullet point,

我有一个场景,我想在表中选择一组记录,然后根据第二个选择将新记录从第一个选择写入表中

我希望从中选择然后写入的表格是:

bullets ------- id product_code catalogue_category_id bullet_text sort_sequence 对于本产品,这给出了4行,项目符号的数量可能因产品而异。结果是:

10001, , Bullet point for testing - 10001, 10001, , 2nd bullet point, 10001, , 3rd bullet point, 10001, , 4th bullet, 这将返回17个产品代码,但根据所选的产品组,代码可能会更少或更多

新纪录包括:

id - this will be auto incremented product_code - this will be the new product code from the second select statement catalogue_category_id - this will be the selected data from the first select statement bullet_text - this will be the selected data from the first select statement sort_sequence - this will be the selected data from the first select statement id-这将自动递增 产品代码-这将是第二条select语句中的新产品代码 Catalog\u category\u id-这将是从第一个select语句中选择的数据 bullet_text-这将是从第一个select语句中选择的数据 排序顺序-这将是从第一个select语句中选择的数据 所以在这个例子中,我会将总共68条新记录写入项目符号中,17个产品代码中的每一个都有4条

我想我需要一个存储过程来完成这项工作,但我已经搜索过了,无法对我所看到的结果了如指掌。非常感谢您的帮助

68条记录将作为新记录写入项目符号表。所选记录可以填充四个字段的全部或任意组合:

product_code, catalogue_category_id, bullet_text, sort_sequence 产品代码、目录、类别、项目符号、文本、排序顺序 基本上,我希望复制所选的记录,但id和产品代码除外。例如,假设我有3个产品代码

10002, 10003 & 10004 10002, 10003 & 10004 使用我的第二个select语句返回,然后我将获得12条新记录,3组4条,几乎与第一个select语句中的初始4条相同,ID将自动递增,产品代码将为

10002 for the first 4 new records 10003 for the next 4 new records 10004 for the last 4 前4项新记录为10002 10003以获取接下来的4项新记录 过去4个月里是10004 我将为每个字段编写所选内容。以您的示例为例,选择的4条记录中有2条在Catalog\u category\u id字段中有数据,那么68条新记录中的34条将在Catalog\u category\u id字段中有数据。

正如我所回答的,您所需要的是
交叉连接

插入项目符号(产品代码、目录、类别、项目符号文本、排序顺序)
选择m.产品代码、b.目录\类别\ id、b.项目符号\文本、b.排序\序列
从项目符号b交叉连接主节点m
其中b.产品代码=10001
m.product_组=3
和m.product_代码10001;

这里是演示

您想在哪里编写
68条新记录
?或者,您的意思是要检索68条记录。如果在第一个
select
语句中给出了记录,并且其中两个已经
catalog\u category\u id
,该怎么办?那么输出是什么呢?嗨,JW,谢谢。我已经回答了你上面的问题,谢谢你的帮助。迈克