按子串分组

Wol*_*ang 8 mysql group-by substring

我有一个字段,如" /site/index?sid=18&sub=321333&tid=site.net&ukey=1234543254".

如何通过字符串的一部分对它进行分组(' sid'url param eg)?
并且params可能处于不同的顺序.(sid在行尾等等)

Hor*_*ren 13

看一下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

UPDATE

这正是你要求的:

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

this_will_be_groupedGROUP BY查询的子句中使用