首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

outer 联接查询

2012-09-02 
outer 连接查询create table test_rightandleft(id integer, basic_id integer, idvalue number(16,2), id

outer 连接查询
create table test_rightandleft
(id integer,
basic_id integer,
idvalue number(16,2),
idcreattime date);
实现的功能是对同一张表信息,不同时间段,同样basicid的
值进行减操作,依照左边表的记录为被减数


以下的SCRIPT是将'2007/11/19/20/53/00'以后的值,减去对应basic_id的值看增加的情况。
select a.baid_l,(a.lvalue-b.rvalue) from
(
select l.basic_id baid_l,l.idvalue lvalue from test_rightandleft l where to_char(idcreattime,'yyyy/mm/dd/hh24/mi/ss')>'2007/11/19/20/53/00'
) a left join
(
select r.basic_id baid_r,r.idvalue rvalue from test_rightandleft r where to_char(idcreattime,'yyyy/mm/dd/hh24/mi/ss')<='2007/11/19/20/53/00'
) b on a.baid_l=b.baid_r



select a.baid_l,(a.lvalue-b.rvalue) from
(
select l.basic_id baid_l,l.idvalue lvalue from test_rightandleft l where to_char(idcreattime,'yyyy/mm/dd/hh24/mi/ss')>'2007/11/19/20/53/00'
) a left join
(
select r.basic_id baid_r,r.idvalue rvalue,r.idcreattime rctime from test_rightandleft r
) b on a.baid_l=b.baid_r and to_char(b.rctime,'yyyy/mm/dd/hh24/mi/ss')<='2007/11/19/20/53/00'



热点排行