我有一个文本字段,如“/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/