我有一个包含多个子字符串的文本字符串,其中我想要计数出现的字符串。我看到了类似问题的解决方案,但我想知道是否可以使用case语句或不创建新表来完成这一任务。
基本上,我使用的是一个数据聚合/分析工具,它只接受非常基本的MySQL语句。
示例:
Paid Search:CLICK, Display:RICH_MEDIA, Display:RICH_MEDIA, Display:RICH_MEDIA, Display:RICH_MEDIA, Display:CLICK, Display:IMPRESSION, Display:IMPRESSION, Display:RICH_MEDIA, Display:RICH_MEDIA, Display:IMPRESSION, Display:CLICK我想提取一个"Display:Rich_Media“的计数
发布于 2016-05-06 19:06:14
在这里,您可以通过以下查询来完成这一任务:
SET @your_string :=
'Paid Search:CLICK, Display:RICH_MEDIA, Display:RICH_MEDIA, Display:RICH_MEDIA, Display:RICH_MEDIA, Display:CLICK, Display:IMPRESSION, Display:IMPRESSION, Display:RICH_MEDIA, Display:RICH_MEDIA, Display:IMPRESSION, Display:CLICK';
SELECT
ROUND(
(
LENGTH(@your_string) - LENGTH(
REPLACE (
@your_string,
"Display:RICH_MEDIA",
""
)
)
) / LENGTH("Display:RICH_MEDIA")
) AS totalOccurrence;解释:
https://stackoverflow.com/questions/37079623
复制相似问题