select b.region_code,count(jk_fee),sum(jk_fee) from rpt.four_fee_show a right join acct_host_route@rpt_to_cenmr b
on(substr(a.phone_no,1,7)=b.route_seg) and year_month=200901 and jk_fee<>0
group by b.region_code;和 select b.region_code,count(jk_fee),sum(jk_fee) from rpt.four_fee_show a right join acct_host_route@rpt_to_cenmr b
on(substr(a.phone_no,1,7)=b.route_seg) where year_month=200901 and jk_fee<>0
group by b.region_code;
有什么区别阿,详细说说,为什么上面能都列出来 ,下面的只能列出关联到的呢 ???

解决方案 »

  1.   

    year_month=200901 and jk_fee<>0
    作为连接条件和作为限制条件肯定有区别的做为连接条件,右边不满足的记录也会被查询出来做为限制条件,右边不满足的记录不会被查询出来如果是inner join,查询出来的记录就没有什么区别
      

  2.   

    第一条语句中,year_month=200901 and jk_fee<>0
    不满足这条的,表A中的值为空,表B照样有值第二条中用where,对整个查询进行条件限制,不满足year_month=200901 and jk_fee<>0
    条件的不会被列出
      

  3.   

    ON后面的是连接条件
    1、
    (substr(a.phone_no,1,7)=b.route_seg) and year_month=200901 and jk_fee<>0
    满足(substr(a.phone_no,1,7)=b.route_seg) and year_month=200901 and jk_fee<>0进行连接操作
    2、
    (substr(a.phone_no,1,7)=b.route_seg)
    满足(substr(a.phone_no,1,7)=b.route_seg)进行连接操作
    3、
    WHERE后面的是过滤条件,通过连接运算后得到关系变量然后再进行过滤。