现在有两个表    
table1
a                           b
小宝                     1
小强                     1
小虎                     1
table2
a                        点击量                       c
小宝                     10                           2008-01-01
小强                     11                           2008-01-01
小宝                     12                           2008-01-02
小强                     9                            2008-01-02
table2表里没有小虎的记录
我想统计小宝,小强,小虎   的在2008-01-01到2008-01-02月的点击量   ,要怎么做啊!!!请各位高手赐教!!!

解决方案 »

  1.   

    table1是当前所有的用户.table2是所有用户的在不同时间的点击量.
    现在是想统计当前所有用户在不同时间的点击量.
      

  2.   

    select sum(点击量    ) ,t1.a from table2 t2,table1 t1
    where t1.a=t2.a(+)
    and c between '2008-01-01' and '2008-01-02月'//自己写
    group by t1.a
      

  3.   

    只要当前用户, 就不要外连接了.select sum(点击量), t1.a from table2 t2, table1 t1 
     where t1.a=t2.a
       and c between to_date('2008-01-01', 'yyyy-mm-dd') and to_date('2008-01-02', 'yyyy-mm-dd')  
     group by t1.a; 
      

  4.   


    select t1.a, NVL(sum(t2.点击量 ) ,0) 点击量 
    from
    (
    select '小寳' a,1 b from dual union
    select '小強',1 from dual union
    select '小虎',1 from dual 
    ) t1
    left join 
    (
    select '小寳' a,10 点击量 , '2008-01-01' c from dual union
    select '小強',11,'2008-01-01'  from dual union
    select '小寳',12,'2008-01-02' from dual union
    select '小強',9,'2008-01-02' from dual 
    ) t2 on t1.a=t2.a and t2.c between '2008-01-01' and '2008-01-02'
    group by t1.a  --------------------------------------------------------
        A 點擊量
    1 小虎 0
    2 小強 20
    3 小寳 22
      

  5.   

    select a.a,nvl(b.dianJL_sum,0)
    from table1 a
    left join (select b.a,sum(dianJL) dianJL_sum
               from table2 b 
               where to_date(c,'yyyy-mm-dd') between to_date('2008-01-01','yyyy-mm-dd') and to_date('2008-01-02','yyyy-mm-dd')       
               group by b.a)
    on a.a=b.a
      

  6.   

    这里的"dianJL"为table2 的第二个字段名
      

  7.   

    select A.a,B.count  from 
     (select  A.a  from table1  A) A,
     (select  B.a ,sum(B.点击量)count from table2 B where xdate between xxx and yyyy group B.a) bwhere  A.a=B.a