mysql - 如何创建具有增量周数的重复记录
问题描述
我正在尝试从表中创建每条记录的 n 个重复项(例如 5 个),并在与每条记录关联的周数上增加一个增量。
假设有一个表格,其列如下 - week, id 并且有一条记录 - 1, John
我希望 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;
推荐阅读
- unity3d - HLSL - 一个浮点数似乎返回了错误的值
- php - 动态复选框和更新 html 页面
- django - 生产服务器上的 Django 电子邮件超时
- java - 在 Spring Boot 中触发 log4j2 的 logger.error() 时触发自定义方法
- mysql - 从 mysql 获取格式正确的日期
- linux - 在 bash 中动态生成命令
- javascript - 围绕框 Three.js 渲染网格
- python - 使用带有约束的 itertools.permutations 来解决旅行商问题
- python - musicbrainzngs:从艺术家搜索中获取 ID
- github - GitHub 操作:没有出现任何事件,工作流是否正在运行?