本文介绍了按子串分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



如何将它分成部分字符串(' sid 'url param eg)?

和params可以按不同的顺序排列( sid 在行尾等)

解决方案

查看MySQL字符串函数:



特别是这看起来很有用:



更新



这正是您所要求的: (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 c $ c> GROUP BY 您的查询条款


I have a field with text like "/site/index?sid=18&sub=321333&tid=site.net&ukey=1234543254".

How can I group it by part of string( 'sid' url param e.g.)?
And params may be in a different order.(sid on the end of line and etc.)

解决方案

Take a look at the MySQL string functions:

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

Especially this looks helpful:

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

UPDATE

This is exactly what you asked for:

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

and use this_will_be_grouped in the GROUP BY clause of your query

这篇关于按子串分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 23:53