gpt4 book ai didi

mysql - 如何使用增量周数创建重复记录

转载 作者:行者123 更新时间:2023-11-29 16:07:49 24 4
gpt4 key购买 nike

我正在尝试从表中创建每条记录的 n 个重复项(例如 5 个),并在与每条记录关联的周数上递增。

假设有一个表,其中包含以下列 - 周、id并且有一条记录 - 1,约翰

我想让John的记录重复5次才能获得-

1, John

2, John

3, John

4, John

5, John

最佳答案

好吧,您可以生成一个包含五列的表格,然后使用它:

select (t.week + x.inc) as week, t.name
from t cross join
(select 0 as inc union all
select 1 as inc union all
select 2 as inc union all
select 3 as inc union all
select 4 as inc
) x;

关于mysql - 如何使用增量周数创建重复记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55560132/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com