本帖最后由 tangwenlong 于 2013-05-19 23:36:29 编辑

解决方案 »

  1.   

    select b.userId,count(*) as myCount,
    sum(clickNum),sum(commNum),sum(shareNum)
    from (
    select shortUrl,    
    SUBSTRING_INDEX(countString23,',',1)+0 as clickNum,   
    SUBSTRING_INDEX(SUBSTRING_INDEX(countString23,',',2),',',-1)+0 as commNum,   
    SUBSTRING_INDEX(countString23,',',-1)+0 as shareNum 
    from url_20130519_hour
    ) a ,main_info_01 b
    where a.shortUrl=b.shortUrl
    group by b.userId
      

  2.   

    版主,我将这些数据插入url_20130519_count 表格报错啊,我在前面加入了
    insert into url_20130519_count  values
    select 语句确实生成了我想要的数据。
    use wburl;
    insert into url_20130519_count  values(select b.userId,count(*) as myCount,     
    sum(clickNum) as clickNum ,sum(commNum) as commNum,sum(shareNum)  as shareNum
    from (     select shortUrl,             SUBSTRING_INDEX(countString23,',',1)+0 as clickNum,            SUBSTRING_INDEX(SUBSTRING_IND
    EX(countString23,',',2),',',-1)+0 as commNum,        
        SUBSTRING_INDEX(countString23,',',-1)+0 as shareNum      from url_20130519_hour ) a ,main_info_01 b where a.shortUrl=b.shortUrl 
    group by b.userId);请版主继续帮忙啊,谢谢!
      

  3.   

    insert into xxx select f1,f2... from yyy
      

  4.   


    是这个样子?use wburl;
    insert into url_20130520_count  select userId,myCount,clickNum,commNum,shareNum from (select b.userId,count(*) as myCount,     
    sum(clickNum) as clickNum ,sum(commNum) as commNum,sum(shareNum)  as shareNum
    from (     select shortUrl,             SUBSTRING_INDEX(countString23,',',1)+0 as clickNum,            SUBSTRING_INDEX(SUBSTRING_IND
    EX(countString23,',',2),',',-1)+0 as commNum,        
        SUBSTRING_INDEX(countString23,',',-1)+0 as shareNum      from url_20130519_hour ) a ,main_info_01 b where a.shortUrl=b.shortUrl 
    group by b.userId);
    报错:
    ERROR 1248 (42000) at line 4: Every derived table must have its own alias求指点啊,
      

  5.   

    上面的insert into表名应该是url_20130519_count