Substring group

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 a string (' sid ' url param eg.g)?
And the parameters may be in a different order. ( sid at the end of the line, etc.)

+6
source share
1 answer

Take a look at the MySQL string functions:

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

This especially looks useful:

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

UPDATE

This is exactly what you requested:

 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 your request

+11
source

Source: https://habr.com/ru/post/920575/


All Articles