使用我有一个MySQL表命名为“内容”包含(AO)领域的“_DATE”和“文本”,例如:指望有多少次一个词被每
_date text
---------------------------------------------------------
2011-02-18 I'm afraid my car won't start tomorrow
2011-02-18 I hope I'm going to pass my exams
2011-02-18 Exams coming up - I'm not afraid :P
2011-02-19 Not a single f was given this day
2011-02-20 I still hope I passed, but I'm afraid I didn't
2011-02-20 On my way to school :)
我寻找一个查询来计算每天使用“希望”和“害怕”字样的次数。换句话说,输出必须是这样的:
_date word count
-----------------------
2011-02-18 hope 1
2011-02-18 afraid 2
2011-02-19 hope 0
2011-02-19 afraid 0
2011-02-20 hope 1
2011-02-20 afraid 1
是否有一个简单的方法来做到这一点,或者我应该只写每学期我不同的查询?我现在有这个,但我不知道该用什么来代替“?”
SELECT COUNT(?) FROM content WHERE text LIKE '%hope' GROUP BY _date
有人可以帮助满足正确的查询吗?
好的答案:)通过使用类似于我的答案的连接,您可以节省这些UNION,只需要将每个单词写一次即可。 – knittl 2012-02-04 17:37:19