gpt4 book ai didi

mysql - 使用sql server根据列中提供的范围将记录拆分为多行

转载 作者:行者123 更新时间:2023-11-29 17:08:48 25 4
gpt4 key购买 nike

我希望使用 sql server 根据列中提供的范围将记录拆分为多行。请提供帮助。

示例源数据集如下 -

account_no    range
abc_111 2001…2010

预期目标数据集如下 -

account_no         range
abc_111 2001
abc_111 2002
abc_111 2003
abc_111 2004
abc_111 2005
abc_111 2006
abc_111 2007
abc_111 2008
abc_111 2009
abc_111 2010

此外,源数据和预期目标数据如附图所示。

最佳答案

您需要一个类似数字的表来拆分数据。您可以自己构建一个:

select sd.account_no, substring_index(range, '...', 1) + n.n - 1
from sourcedata sd join
(select 1 as n union all
select 2 union all
. . .
select 10
) n
on n.n >= 1 and
n.n <= substring_index(range, '...', -1) - substring_index(range, '...', 1);

关于mysql - 使用sql server根据列中提供的范围将记录拆分为多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51958564/

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