8

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

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

4

1 回答 1

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

更新

这正是您所要求的:

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

this_will_be_groupedGROUP BY查询的子句中使用

于 2012-07-16T11:43:15.787 回答