我有一个错误表,看起来像
"file not configured [filename1]"
"file not configured [filename2]"
"file not configured [filename3]"
"A bomb went off!!"
我想要做的是获取错误发生的列表,例如
text occurrences
____________________________________
file not configured.. 3
a bomb went off!! 1
是否可以在sqlite中运行查询以检查前x个字符的相似性?
答案 0 :(得分:1)
您可以尝试聚合每条错误消息的特定数量的第一个字符:
SELECT
SUBSTR(text, 1, 12) AS text, -- or however long a substring you want
COUNT(*) AS occurrences
FROM errors
GROUP BY
SUBSTR(text, 1, 12);
请注意,上述查询严格不符合ANSI标准,因为GROUP BY
子句包含列的功能。为了解决这个问题,我们可以用子查询重写。