使用SQL中的拆分记录
我有一张具有以下记录
前缀 | 以下前缀 | 开始端部 | div | 行业 |
---|---|---|---|---|
1AB | 00001 | 99999 | li 1ab | ri |
1AB | 00527 | 00527 | 00528 mhug | ri |
我想将其分配为
前缀 | ri 1 ab ri ri 1 | end | div | 行业 |
---|---|---|---|---|
1AB | 00001 | 99999 | lpsd | ri |
1ab | 00527 00527 | 00528 | mhug | ri |
1 ab | ri 1 ab ri | 00527 | 1ab | ri |
ab 00529999999999999999999999999999999999999999999.如果您看到的是因为我们有一个具有相同前缀的记录,但开始和结束是不同的,我想将第一个记录分为2个记录,一个从00001到00526,再到00529,再到99999
。 SQL查询
I have an table with the below records
PREFIX | BEGIN | END | DIV | INDUSTRY |
---|---|---|---|---|
1AB | 00001 | 99999 | LPSD | RI |
1AB | 00527 | 00528 | MHUG | RI |
I want to split it as below
PREFIX | BEGIN | END | DIV | INDUSTRY |
---|---|---|---|---|
1AB | 00001 | 99999 | LPSD | RI |
1AB | 00527 | 00528 | MHUG | RI |
1AB | 00529 | 99999 | LPSD | RI |
If you see as because we have a record with the same prefix but begin and end are different, i want to split the first record into 2 records, one from 00001 to 00526 and 00529 to 99999.
Is it possible to perform the same using the SQL query
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这有效(但是它需要更大的数据集来正确测试):
对于示例数据:
输出:
db<<>> gt; gt; gt; A3F630E04D8DBBB rel =“ nofollow noreferrer”>此处
I think this works (but it would need a bigger data set to test it properly):
Which, for the sample data:
Outputs:
db<>fiddle here
首先,在保留单词后(例如开始,结束...),命名列并不是一个好习惯。可以使用这样的模型子句来解决这...
希望它会有所帮助。问候...
First of all it is not a good practice to name columns after reserved words (like Begin, End ...). This could be solved using MODEL clause like this...
Hopefully it will help. Regards...