mysql - 按子串分组

标签 mysql group-by substring

我有一个文本字段,如“/site/index?sid=18&sub=321333&tid=site.net&ukey=1234543254”。

如何按字符串的一部分(例如 'sid' url 参数)对其进行分组?
并且参数可能有不同的顺序。(sid 在行尾等)

最佳答案

看看 MySQL 字符串函数:

http://dev.mysql.com/doc/refman/5.0/en/string-functions.html

特别是这看起来很有帮助:

http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_substring-index

更新

这正是您所要求的:

SELECT SUBSTRING_INDEX(SUBSTRING_INDEX("/site/index?sid=18&sub=321333&tid=site.net&ukey=1234543254", 'sid=', -1), '&', 1) AS this_will_be_grouped

并在查询的 GROUP BY 子句中使用 this_will_be_grouped

关于mysql - 按子串分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11503393/

相关文章:

php - 当我们多次使用 mysqli_query 时,mysqli_num_rows 返回无效计数

mysql - 如何在mysql中创建一个以unicode字符串作为表名的表?

php - 替换单引号和双引号

python - 在 groupby 之后展开由 lambda 函数创建的列表

Python:根据 id 和时间范围对对象列表进行分组

python - Pandas Multiindex Groupby 聚合列与另一列的值

python - 在网站中两个字符串的子字符串之间提取

mysql - 在多行上使用 LEFT JOIN 简化我的 SQL

python - 创建所有子集的序列作为文本字符串列表

substring - ABL 子字符串 1 个字符到 2 个字符