寻找一种方法来比较mysql中组合的外观

时间:2015-07-02 16:43:44

标签: php mysql bigdata

我有一个BI任务,在我看来非常有趣,我想得到一些帮助,以解决它。 我有2个数据集 - 转换和点击。 转化表:

 id     Rev    Click_id     
  1      2$      1            
  2      3$      2            
  3      1$      3
  4      2$      5

点击表:

   id     Date      Click_data
    1      2.6.2015 {"country:US","Device:Android","Domain:a.com"}
    2      2.6.2015 {"country:US","Device:Android","Domain:b.com",Size=300X250}
    3      2.6.2015 {"country:GB","Device:Android","Domain:b.com",Size=300X250}
    4      2.6.2015 {"country:GB","Device:iphone","Domain:b.com",Size=300X50}
    5      2.6.2015 {"country:GB","Device:iphone","Domain:b.com"}
    6      2.6.2015 {"country:GB","Device:Android","Domain:b.com"}
    7      2.6.2015 {"country:GB","Device:iphone","Domain:b.com"}
    8      2.6.2015 {"country:GB","Device:Android","Domain:b.com","Size=300X250"}

Click数据始终为JSON格式,可以有1-N个字段 现在我想得到的是以下结果: 我需要找到转换

的点击数据的组合

第1阶段 - 基于转化数据的最佳组合:

  count   country     device    size     Domain
   1        US      "ANDROID"    ''       "a.com"
   2        US      "ANDROID"  '300X250'  "b.com"
   1        GB      "IPHONE"     ''       "b.com"

现在我到了这个阶段,允许灵活的Group in the out of Text字段和一些PHP代码创建一个Dimensions Json值列表来创建Query。 查询示例:

PHP代码 - >生成计数维度列表

查询:

    SELECT 
    count(*)as count,
    trim( both "}" from      substring_index(substring_index(if(locate('"country":',click_data) > 0,click_data, null), '"country":',-1),',',1)) as country,

    trim( both "}" from           substring_index(substring_index(if(locate('"Device":',click_data) > 0,click_data, null), '"Device":',-1),',',1)) as Device,

    trim( both "}" from      substring_index(substring_index(if(locate('"Domain":',click_data) > 0,click_data, null), '"country":',-1),',',1)) as Domain,

    trim( both "}" from      substring_index(substring_index(if(locate('"Size":',click_data) > 0,click_data, null), '"country":',-1),',',1)) as Size,

    group by
    trim( both "}" from      substring_index(substring_index(if(locate('"country":',click_data) > 0,click_data, null), '"country":',-1),',',1)) as country,

    trim( both "}" from           substring_index(substring_index(if(locate('"Device":',click_data) > 0,click_data, null), '"Device":',-1),',',1)) as Device,

    trim( both "}" from      substring_index(substring_index(if(locate('"Domain":',click_data) > 0,click_data, null), '"country":',-1),',',1)) as Domain,

    trim( both "}" from      substring_index(substring_index(if(locate('"Size":',click_data) > 0,click_data, null), '"country":',-1),',',1)) as Size

   ORDER BY count(*) DESC;

现在我希望对Click Table和同一个Query做同样的事情,这样我就可以创建这个结果:

 Stage 1 - The Best Combination

Count_clicks  count_convs   country     device    size     Domain
      1            1          US      "ANDROID"    ''       "a.com"
      3            2          US      "ANDROID"  '300X250'  "b.com"
      2            1          GB      "IPHONE"     ''       "b.com"

我希望找到一种方法,将Json Sub String操作聚合的点击次数(您可以将其视为维度)添加到转化次数相似的计数,以查看生成的点击次数这种组合是为了获得真实的转换率。

谢谢你的帮助!

0 个答案:

没有答案