【发布时间】:2013-09-20 19:18:03
【问题描述】:
我有一个看起来像这样的数据集
id | sentence | tags
1 | "people walk dogs in the park" | "pet park health"
2 | "I am allergic to dogs" | "allergies health"
是否可以使用sql查询找到每个标记词和每个句子词之间的数量共现?这会很困难,因为您必须解析每个标签和句子条目。
它可能看起来像
select sentence_word,tag_word,count(id)
from
(select id,sentence_word
from table)A
join
(select id, tag_word
from table)B
on A.id=B.id
group by sentence_word,tag_word
除非我知道这两个子查询不正确
以下是一些示例结果
tag_word | sentence_word | count(id)
"walk" |"pet" |1
"health" |"dogs" |2
"allergies" |"dogs" |1
【问题讨论】:
-
请发布样本结果。
-
如果你规范化标签,你会帮助自己。
-
对不起。我没有任何结果,我只是想找到一种策略来解决这个问题。
-
共现是指具有共同标签的句子数吗?例如。在上面的例子中,它应该返回 2 表示健康,1 表示其余部分?
-
对不起@danihp,我刚刚意识到我误解了你所说的,我添加了一些示例结果。
标签: sql parsing mysqli split unpivot