我有一个字符串数组和一个带有文本类型列的表格。我想列出哪个字符串在表中任何一行的指定列中出现了多少次。有一种方法可以用一个查询来做到这一点吗?查询列出哪个字符串在表中出现了多少个字符?
Example;
$strings = array('test', 'sth');
Table;
id | someTextColumn
-------------------
1 | abc tests
2 | sthab
3 | teststh
4 | abcd
5 | sth
Expected result;
str | occurences
-----------------
test | 2
sth | 3
这是工作,除零发生。有没有办法添加它? –
@m_poorUser。 。 。是的,你需要一个外连接(这也需要将'count(*)'改为'count(id)'。 –
'count(totest.id)'应该是'count(t.id)'。作品,谢谢。 –