我有一个带有“ /site/index?sid=18&sub=321333&tid=site.net&ukey=1234543254
”之类的文本的字段。
如何按字符串的一部分(' sid
' url param eg)对它进行分组?
并且参数的顺序可能不同。(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
并this_will_be_grouped
在GROUP BY
查询的子句中使用