两个表的结构一样,表a,表b,表a中的数据如下:
id ye rq ts
1 1200 2009-02-01 80
2 1500 2009-03-01 140
表b中的数据如下:
id ye rq ts
1 200 2009-02-01 80想要的结果如下:
id ye rq ts
1 1000 2009-02-01 80
2 1500 2009-03-01 140解释:
表a,b中相同rq,ts的数据,ye进行相减,高手指教
id ye rq ts
1 1200 2009-02-01 80
2 1500 2009-03-01 140
表b中的数据如下:
id ye rq ts
1 200 2009-02-01 80想要的结果如下:
id ye rq ts
1 1000 2009-02-01 80
2 1500 2009-03-01 140解释:
表a,b中相同rq,ts的数据,ye进行相减,高手指教
条件改下,
select b.id, a.ye - b.ye as ye, rq,ts from a,b where a.rq = b.rq and a.ts = b.ts;
a,b where a.rq=b.rq(+) and a.ts=b.ts(+)
a,b where a.rq=b.rq(+) and a.ts=b.ts(+)
a,b where to_char(a.rq,'yyyy-mm-dd')=to_char(b.rq,'yyyy-mm-dd')(+) and a.ts=b.ts(+)
select a.id,a.ye-nvl(b.ye,0) ye,a.rq,a.ts from
a,b where a.rq=b.rq(+) and a.ts=b.ts(+)ID YE RQ TS
1 1000 a 80
2 1500 b 140
可以了,关键在nvl(b.ye,0)这个,谢谢了