【问题标题】:Group by substring按子字符串分组
【发布时间】:2012-07-15 05:55:12
【问题描述】:

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

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

【问题讨论】:

    标签: mysql group-by substring


    【解决方案1】:

    看看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

    【讨论】:

      猜你喜欢
      • 2011-11-20
      • 2016-12-24
      • 1970-01-01
      • 2013-12-18
      • 1970-01-01
      • 2015-12-18
      • 1970-01-01
      • 2013-10-11
      • 1970-01-01
      相关资源
      最近更新 更多