MySQL存储过程设计问题V2.是回避还是层次结构? [英] MySQL Stored Procedure Design Problem V2. Recusion or Hierarchy?
问题描述
假设我们有一个名为Connected
的表,其中的列node_1
和node_2
均为整数类型,并且其中包含一些数据.
Suppose we have a table named Connected
, with column node_1
and node_2
, both integer type, and some data in it.
它看起来像这样:
`node_1` `node_2`
A B
C D
B C
B F
C W
D N
D Q
.
.
. Much much much more
.
我想做的是扩展此表,然后收集所有关系.例如,如果我们可以通过路径"ABCDQ"(由旧表"AB,BC,CD,D-Q"定义)从"A"到"Q",那么我们说"A"和"Q"可以连接,并将这对插入新表.
What Im trying to do is expand this table, and then collect all relations. For instance, if we can travel from 'A' to 'Q' with path 'A-B-C-D-Q' ( defined by the old table, 'A-B, B-C, C-D, D-Q'), we say that 'A' and 'Q' can be connected, and insert this pair into new table.
这样,结果表应如下所示:
Such that, the result table should looks like this:
`node_1` `node_2`
A B
A C
A D
A F
A N
A Q
A W
B C
B D
B F
B N
B Q
B W
C D
C N
C Q
C W
D Q
D N
感谢所有帮助!
将单词节点"更改为组", 连接"到包含",做到了 听起来更合理?我很抱歉 语法或其他与之相关的语言 问题问题:)
Change the word "Node" to "Group", "connected" to "contains", does it sound more reasonable? Im Sorry for my gramma or any other language related problemssss :)
推荐答案
与我的其他解决方案相同,只需在SELECT中将字符周围的ASCII()用作其ascii值即可.
Same as my other solution, just use ASCII() around the character to the its ascii value in the SELECT.
PS.由于我们在另一个问题上的交谈.我印象深刻,这是您找到一个当务之急的解决方案的真正内容.请记住,SQL是一种声明性语言.
PS. due to our conversation in the other question. Im getting the impression your really content of finding a imperative solution for this. Remember, SQL is a declarative language.
这篇关于MySQL存储过程设计问题V2.是回避还是层次结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!