我有一张桌子上写着: ID;NAME
1-dog
2-log
3-for然后,我有一个包含字符: ID;NAME的表。
1-_og
2-_or
3-_ot现在,我有了第三个关系表(让我们称它为words_and_characters),在这里,我希望将来自表单词的id和来自“匹配”表字符的id放在其中。由ID、WORD_ID、CHARACTER_ID组成的表id
在上面的示例中,表words_and_characters应该包含以下内容:
1-1-1 (the match is "dog" and "_og")
2-2-1 (the match is "log" and "_og")
3-3-2 (the match is "for" and "_or")我开始使用第一个游标编写一个存储过程,用于遍历表字符,如下所示:
select id, name from characters;把日期写成这样:
FETCH curs1 INTO i,n;现在,在每次迭代中,我都想做这样的事情:
select * from words where name like n;嗯,恐怕这有点无效,特别是如果有很多数据的话。你觉得有什么更好的方法吗?也许我也可以避免编写存储过程,而只是有某种改进的sql?
发布于 2014-06-23 18:33:00
使用连接:
INSERT INTO words_and_characters (word_id, character_id)
SELECT w.id, c.id
FROM words AS w
JOIN characters AS c ON w.name LIKE c.namehttps://stackoverflow.com/questions/24372755
复制相似问题