1
我嘗試計數事件,並通過添加組後計數出現不GROUP_CONCAT
我的表:
id | book | chapter | text
1 | 1 | 1 | 'hello hello world'
2 | 1 | 2 | 'hello hello hello hello'
3 | 1 | 3 | 'world'
4 | 1 | 4 | 'hello test'
我執行我的要求:
SELECT
book,
chapter,
group_concat(text) as text,
ROUND (
(
LENGTH(group_concat(text))
- LENGTH(REPLACE (group_concat(text), "hello", ""))
)/LENGTH("hello")
) AS 'count'
FROM my_table
WHERE book=43
GROUP BY chapter, book
我想這樣的結果:
book | chapter | count
----------------------
43 | 1 | 2
43 | 2 | 4
43 | 3 | 0
43 | 4 | 1
它的工作!
但我必須重新定義一個變量group_concat_max_len有:
SET SESSION group_concat_max_len = 1000000;
我的服務器是一個mutualized服務器,我沒有權限(設置全局,例如)。
我想執行另一個請求,在沒有group_concat_max_len的情況下得到相同的結果,你有什麼想法嗎?
這是我會採取的方法,只是在個人的「文本」中計算出現的事件,然後做計數的聚合。 +10。 (我同意Gordon。對於一組字符串中的字符串計數的直接「計數」,不需要「GROUP_CONCAT」聚合。) – spencer7593
@Gordon真棒!謝謝 !! –