right join 和(+)

今天遇到个问题,是有关oracle中的right join 和(+)

很奇怪的问题 看了很久,才知道是哪的问题

--right join

select /*l.trade_city_code as city_code ,*/
                       t.trade_type as trade_type,
count(distinct l.trade_id) as count
                  from tf_bh_trade l
                 right join (select *
                              from uop_crm3.td_s_tradetype y
                             where y.trade_type_code in
                                   (127, 710, 532, 1029, 1025, 149, 141, 100, 419,
                                   1275, 80, 1274, 615, 416, 1060,124, 311, 1028, 116, 330,
                                    310, 126, 122, 12, 137, 143, 128, 279, 278, 136,
                                    110, 133, 70, 139, 31, 290, 30, 250, 131, 381, 690,
                                    72, 60, 20, 190, 132, 120, 160, 268, 269, 270, 271, 272,
                                    273, 274, 275, 276, 277, 192, 71, 340, 63)) t 
                                    on l.trade_type_code =   t.trade_type_code
                                      and t.eparchy_code ='0312' and l.eparchy_code ='0312'
and l.trade_staff_id <> 'SUPERUSR'
and l.trade_type_code <= 7000
and l.accept_date >=
to_date(to_char(trunc(sysdate-1),'yyyy-mm-dd') ||' 00:00:01','yyyy-mm-dd hh24:mi:ss')
and accept_date <
to_date(to_char(trunc(sysdate-1),'yyyy-mm-dd') ||' 23:59:59','yyyy-mm-dd hh24:mi:ss')
                 group by /*l.trade_city_code,*/t.trade_type
                 order by /*l.trade_city_code,*/t.trade_type;

--(+)

select /*l.trade_city_code as city_code ,*/
                       t.trade_type as trade_type,
count(distinct l.trade_id) as count
                  from uop_crm3.tf_bh_trade l
               , (select *
                              from uop_crm3.td_s_tradetype y
                             where y.trade_type_code in
                                   (127, 710, 532, 1029, 1025, 149, 141, 100, 419,
                                   1275, 80, 1274, 615, 416, 1060,124, 311, 1028, 116, 330,
                                    310, 126, 122, 12, 137, 143, 128, 279, 278, 136,
                                    110, 133, 70, 139, 31, 290, 30, 250, 131, 381, 690,
                                    72, 60, 20, 190, 132, 120, 160, 268, 269, 270, 271, 272,
                                    273, 274, 275, 276, 277, 192, 71, 340, 63)
                                    and y.eparchy_code ='0312'
                                    ) t 
                                    where l.trade_type_code(+) =  t.trade_type_code
                                      and l.eparchy_code ='0312'
and l.trade_staff_id <> 'SUPERUSR'
and l.trade_type_code <= 7000
and l.accept_date >=
to_date(to_char(trunc(sysdate-1),'yyyy-mm-dd')  ||' 00:00:01','yyyy-mm-dd hh24:mi:ss')
and l.accept_date <
to_date(to_char(trunc(sysdate-1),'yyyy-mm-dd') ||' 23:59:59','yyyy-mm-dd hh24:mi:ss')
                 group by /*l.trade_city_code,*/t.trade_type
                 order by /*l.trade_city_code,*/t.trade_type;

上面这两个语句乍一看,执行结果应该是一致的,但其实不然,然后我就各种揣摩,咨询别人,后来终于知道错误之处了

以下语句是修改之后的

--(+)

select /*l.trade_city_code as city_code ,*/
                       t.trade_type as trade_type,
count(distinct l.trade_id) as count
                  from (SELECT * FROM uop_crm3.tf_bh_trade l
                   where l.eparchy_code ='0312'
and l.trade_staff_id <> 'SUPERUSR'
and l.trade_type_code <= 7000
and l.accept_date >=
to_date(to_char(trunc(sysdate-1),'yyyy-mm-dd')  ||' 00:00:01','yyyy-mm-dd hh24:mi:ss')
and l.accept_date <
to_date(to_char(trunc(sysdate-1),'yyyy-mm-dd') ||' 23:59:59','yyyy-mm-dd hh24:mi:ss'))l
               , (select *
                              from uop_crm3.td_s_tradetype y
                             where y.trade_type_code in
                                   (127, 710, 532, 1029, 1025, 149, 141, 100, 419,
                                   1275, 80, 1274, 615, 416, 1060,124, 311, 1028, 116, 330,
                                    310, 126, 122, 12, 137, 143, 128, 279, 278, 136,
                                    110, 133, 70, 139, 31, 290, 30, 250, 131, 381, 690,
                                    72, 60, 20, 190, 132, 120, 160, 268, 269, 270, 271, 272,
                                    273, 274, 275, 276, 277, 192, 71, 340, 63)
                                    and y.eparchy_code ='0312'
                                    ) t --受理动作
                                    where l.trade_type_code(+) =  t.trade_type_code
                                    
                 group by /*l.trade_city_code,*/t.trade_type
                 order by /*l.trade_city_code,*/t.trade_type;

原来,跟where条件语句的放置位置是有关系的,即这句where l.eparchy_code ='0312'
and l.trade_staff_id <> 'SUPERUSR'
and l.trade_type_code <= 7000
and l.accept_date >=
to_date(to_char(trunc(sysdate-1),'yyyy-mm-dd')  ||' 00:00:01','yyyy-mm-dd hh24:mi:ss')
and l.accept_date <
to_date(to_char(trunc(sysdate-1),'yyyy-mm-dd') ||' 23:59:59','yyyy-mm-dd hh24:mi:ss')),虽然不太清楚原理,但确实解决问题了,继续学习ing...

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值