right join 和(+)
来源:互联网 发布:淘宝复刻潮牌店铺排行 编辑:程序博客网 时间:2024/05/14 19:06
今天遇到个问题,是有关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...
- right join 和(+)
- left join 和 right join
- INNER JOIN 、 LEFT JOIN 和 RIGHT JOIN
- inner join、Left Join和Right join
- left join和right join的区别
- LEFT JOIN 和 RIGHT JOIN 运算
- SQL 中 Left Join 和Right Join
- mysql的left join 和 right join
- Left/right join 和inner join 区别
- 面试之SQL(2)--left join, inner join 和 right join的区别
- 面试之SQL(2)--left join, inner join 和 right join的区别
- left join和right join和inner join的区别
- inner join 和 lefe join on 和right join区别
- left join 和 right join 和 inner join区别
- LEFT JOIN 、RIGHT JOIN和INNER JOIN 运算
- Inner join , Left join 和Right join 的区别
- left join 和 right join ,inner join的区别
- left join ,right join 和 inner join 的区别
- 计算C++程序运行时间总结
- U-Boot SD (Secured Digital card) Support
- 学习FFmpeg API – 解码视频
- 我的Symbian编程回忆录
- 实习第3天
- right join 和(+)
- 0708
- Linux学习手记(一)——Linux系统中主分区、扩展分区和逻辑分区的区别与联系
- 播放器源码
- 12864液晶采用单片机内部显示缓冲的程序
- Fs2410上基于linux触摸屏的移植
- Linux下时间计算
- 使用Android中的网络连接
- C++中声明和定义知识点的梳理