加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

oracle合并两个不一样的结果集

发布时间:2020-12-12 14:35:34 所属栏目:百科 来源:网络整理
导读:oracle查询两个结果集合并 1:通过union 和 union all 合并,但是前提了查出来的结果集要一致 2:如果两个结果集不一致,就要用到left join on 比如: 有a表,我想要求7月和8月的前三天的价格都是多少 select * from a; 月份 (month) 日期(day) 价格(p
07 1 $1600 07 2 $12 07 3 $1 07 … … 08 1 $1500 08 2 $11 08 3 $2 08 … …

用一个sql完成就是这样:

select a.price 当前月份价格,b.price 上月份价格,a.day 账期 from ( select t.price,t.day from a t where t.month = to_number('201708') and t.day <= '03' ) a left join ( select t.price 上月份价格,t.day from a t where t.month = to_number('201708')-1 and t.day <= '03' ) b on a.day=b.day order by a.day

这样就在一个结果集里体现出来了。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

oracle查询两个结果集合并

1:通过union 和 union all 合并,但是前提了查出来的结果集要一致
2:如果两个结果集不一致,就要用到left join on

比如:
有a表,我想要求7月和8月的前三天的价格都是多少
select * from a;

月份 (month) 日期(day) 价格(price)
    推荐文章
      热点阅读