[英]Mysql - Replace from multiple rows into one row
I have a problem i'm not sure how to solve. 我有一个问题,我不确定如何解决。
To simplify my problem there is a table with links: 为了简化我的问题,有一个带有链接的表:
fk linkid link 1 1 www.stackoverflow.com 1 2 www.google.com 1 3 www.cnn.com 2 4 www.other.com
Then i have another table with a string-column where a user can insert these keys and then it should replace them. 然后我有另一个带有字符串列的表,用户可以在其中插入这些键,然后将其替换。 You enter a key like L{a number}, like L1.
您输入像L {a number}这样的键,例如L1。 "L1" should then be replaced with linkid 1..
然后应将“ L1”替换为链接ID 1。
id string_column 1 "Hi my first link is {L1]. More text {L1} {L1} {L3} {L2}" 2 "Go here: {L4}"
So when i join them for id 1 i get this: 因此,当我加入他们的ID 1时,我得到了:
id linkid link string_column 1 1 www.stackoverflow.com "Hi my first link is {L1]. More text {L1} {L1} {L3} {L2}" 1 2 www.google.com "Hi my first link is {L1]. More text {L1} {L1} {L3} {L2}" 1 3 www.cnn.com "Hi my first link is {L1]. More text {L1} {L1} {L3} {L2}"
What i would like to get is: 我想得到的是:
id string_column 1 "Hi my first link is www.stackoverflow.com. More text www.stackoverflow.com www.stackoverflow.com www.cnn.com www.google.com"
Is it possible in mysql to write such an sql? 有可能在mysql中编写这样的sql吗? As you can see above i need to make a replace on 1 column but get the values from multiple rows and then only return 1 per id.
如您在上面看到的,我需要对1列进行替换,但是要从多行中获取值,然后每个id只返回1。
Since the system is already the way it is i can't change the setup but just have to find a way to get this right. 由于系统已经是它的样子,所以我不能更改设置,而只需要找到一种方法来解决这个问题。
the only way I see to do this would be a script doing the work, where you take out all the sentences, cut the number from the L, search the corresponding link and replace all {L1} by that link. 我唯一看到的方法是执行该脚本的脚本,在该脚本中,您删除所有句子,从L处剪下数字,搜索相应的链接,然后用该链接替换所有{L1}。 then you update the db with the new string.
然后使用新字符串更新数据库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.