我现在有2张表 
第一张表的结构是
id  date        projectid  resourceid  entryid click
1   2008-01-10  1          1           1       2 
1   2008-01-11  1          1           1       1
1   2008-01-12  1          1           1       2
1   2008-01-11  1          1           1       1
第二张表的结构是
id  date        projectid  resourceid  entryid pv
1   2008-01-10  1          1           1       1 
1   2008-01-11  1          1           1       1
1   2008-01-12  1          1           1       1
1   2008-01-11  1          1           1       1我想实现2步 首先分别把各自表里面的重复date的数据整合
第一张表
id  date        projectid  resourceid  entryid click
1   2008-01-10  1          1           1       2 
1   2008-01-11  1          1           1       2
1   2008-01-12  1          1           1       2
第二张表
id  date        projectid  resourceid  entryid pv
1   2008-01-10  1          1           1       1 
1   2008-01-11  1          1           1       2
1   2008-01-12  1          1           1       1然后再将两个表整合成
date        projectid  resourceid  entryid click pv
2008-01-10  1          1           1       2     1
2008-01-11  1          1           1       2     2
2008-01-12  1          1           1       2     1希望能够得到一句sql语言来实现,多句也可以 谢谢 
希望我描述的大家都看懂了~

解决方案 »

  1.   

    本帖最后由 libin_ftsafe 于 2008-01-15 14:22:42 编辑
      

  2.   

    代码如下:
    select
        a.id,a.date,a.projectid,a.resourceid,a.entryid,a.click,b.pv
    from
        (select id,date,projectid,resourceid,entryid,sum(click) as click from 表1 group by id,date,projectid,resourceid,entryid) a,
        (select id,date,projectid,resourceid,entryid,sum(pv) as pv from 表2 group by id,date,projectid,resourceid,entryid) b
    where
        a.id=b.id and a.date=b.date and a.projectid=b.projectid and a.resourceid=b.resourceid and a.entryid=b.entryid