我有一個字符串數組和一個帶有文本類型列的表格。我想列出哪個字符串在表中任何一行的指定列中出現了多少次。有一種方法可以用一個查詢來做到這一點嗎?查詢列出哪個字符串在表中出現了多少個字符?
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)'。作品,謝謝。 –