Spilit以逗号分隔SQL中的列 [英] Spilit 2 comma separated Columns in SQL
本文介绍了Spilit以逗号分隔SQL中的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在SQL表中有这样的数据
Id |服务|国家
_________________________
1 | A,B | E,F
2 | A1,B1 | E1,F1
所需结果
Id |服务|国家
_________________________
1 | A | E
1 | A | F $ / $
1 | B | E
1 | B | F $ / $
2 | A1 | E1
2 | A1 | F1
2 | B1 | E1
2 | B1 | F1
感谢advace
Hi ,
I have data like this in SQL Table
Id | Services | Country
_________________________
1 | A,B | E,F
2 | A1,B1 | E1,F1
Desired Result
Id | Services | Country
_________________________
1 | A | E
1 | A | F
1 | B | E
1 | B | F
2 | A1 | E1
2 | A1 | F1
2 | B1 | E1
2 | B1 | F1
Thanks in advace
推荐答案
首先,不要存储信息,除非你真的,真的必须 - 正确地做一两个额外的表似乎更多的工作,但它意味着你不必处理这样的问题(他们变得更糟,相信我 - 这只是问题设计的开始只是因为后来这个问题导致修复它们已经太晚了......)
Havign说,这是可能的。令人讨厌,但可能:转换列中逗号分隔的数据行选择 [ ^ ]
First, don't store info like that unless you really, really have to - doing it properly with an extra table or two seems like more work, but it means you don;t have to deal with problems like this (and they get worse, believe me - this is just the start of the problems designs like this cause later, when it's too late to fix them...)
Havign said that, it's possible. Nasty, but possible: Converting comma separated data in a column to rows for selection[^]
这篇关于Spilit以逗号分隔SQL中的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文