select k,sum(decode(lb,1,1,0)) lb1,sum(decode(lb,2,1,0)) lb2,sum(decode(lb,3,1,0)) lb3 from b group by k

解决方案 »

  1.   

    谢谢waterfirer(水清),没有关联上表a呀!汗汗
      

  2.   

    select a.k, count(decode(b.lb,1,1,null)) lb1 , count(decode(b.lb,2,1,null)) lb2, 
           count(decode(b.lb,3,1,null)) lb1
    from tt_a a 
    left join tt_b b on a.k = b.k 
    group by a.k在A表的k字段上建立索引,在B表的k字段上建立索引
      

  3.   

    谢谢,xiaoxiao1984(笨猫儿^_^),再次请教 如何还要实现翻页呢,表A的记录很多.假如20条一页
      

  4.   

    补充说明一下,在表B中不一定包含所有表A中的记录!
    -------------
    做个外连接关联以下就行了
    select a.k,sum(decode(b.lb,1,1,0)) lb1,sum(decode(b.lb,2,1,0)) lb2,sum(decode(b.lb,3,1,0)) lb3 from a,b where a.k=b.k(+) group by a.k
      

  5.   

    谢谢waterfirer(水清) ,xiaoxiao1984(笨猫儿^_^) 结贴!