oracle 列相减——(Oracle分析函数Lead(),Lag())
lag和lead函数,用于取出数据的前n行的数据和后n行的数据,当然要和over(order by)一起组合
with tmp as(
select '' id ,'aa' name from dual union all
select '' id ,'bb' name from dual
)
select a.*,
lag(name,1) over (order by id desc) lag
from tmp a
select * from
(
select t1.yin_name yin_name01,t2.yin_name yin_name02,t1.fluoride-t2.fluoride fluoride,t1.ysn-t2.ysn ysn,t1.jsn-t2.jsn jsn,
t1.jhsn-t2.jhsn jhsn,t1.chloride-t2.chloride chloride,t1.nitrite-t2.nitrite nitrite,t1.nitrate-t2.nitrate nitrate,
t1.wersn-t2.wersn wersn,t1.dersn-t2.dersn dersn,t1.bersn-t2.bersn bersn,t1.sulfate-t2.sulfate sulfate,
t1.yersn-t2.yersn yersn,t1.yin_date yin_date01 ,t2.yin_date yin_date02
from
(select * from zd_yinlz where instr(yin_name,'MO')=0 and instr(yin_name,'BLK')=0) t1
,
(
select t.*,lead(t.yin_date)over(order by yin_date) enddate from
(select * from zd_yinlz where instr(yin_name,'MO')>0 order by yin_date ) t
) t2
where t1.yin_date >= t2.yin_date and t1.yin_date < t2.enddate
)
union
select * from
(
select t1.yin_name yin_name01,t2.yin_name yin_name02,t1.fluoride-t2.fluoride fluoride,t1.ysn-t2.ysn ysn,t1.jsn-t2.jsn jsn,
t1.jhsn-t2.jhsn jhsn,t1.chloride-t2.chloride chloride,t1.nitrite-t2.nitrite nitrite,t1.nitrate-t2.nitrate nitrate,
t1.wersn-t2.wersn wersn,t1.dersn-t2.dersn dersn,t1.bersn-t2.bersn bersn,t1.sulfate-t2.sulfate sulfate,
t1.yersn-t2.yersn yersn,t1.yin_date yin_date01,t2.yin_date yin_date02
from
(select * from zd_yinlz where instr(yin_name,'MO')=0 and instr(yin_name,'BLK')=0) t1
,
(select * from
(select * from zd_yinlz where instr(yin_name,'MO')>0 order by yin_date desc) where rownum = 1) t2
where t1.yin_date >= t2.yin_date
)

oracle 列相减——(Oracle分析函数Lead(),Lag())的更多相关文章
- oracle 日期相减
oracle日期相减2012-02-10 12:18--MONTHS_BETWEEN(date2,date1) 给出date2-date1的月份 SQL> select months_betwe ...
- oracle 日期相减 转载
转自 http://hi.baidu.com/juanjuan_66/blog/item/cf48554c9331fbe6d62afc6a.html oracle日期相减2012-02-10 12 ...
- Oracle 时间相减得出毫秒、秒、分、时、天,,【转】
http://blog.csdn.net/redarmy_chen/article/details/7351410 oracle 两个时间相减默认的是天数 oracle 两个时间相减默认的是天数*24 ...
- awk 两列相减
cat http.txt |awk -F ':' '{print($2-$3)}' 百度文库
- oracle列合并
在很多场合,我们会须要用到oracle列合并,oracle提供了一些方法用于把某列的多行数据合并成一行. 一.10G曾经使用WMSYS.WM_CONCAT wmsys.wm_concat将字段的值 ...
- numpy 数组相减
a与b的每一列相减
- oracle 两个时间相减
oracle 两个时间相减默认的是天数 oracle 两个时间相减默认的是天数*24 为相差的小时数 oracle 两个时间相减默认的是天数*24*60 为相差的分钟数 oracle 两个时间相减默认 ...
- oracle的日期相减
oracle的日期相减 : 两个date类型的 日期相减,得到的是天数,可能是带小数点的.如下:
- oracle两时间相减得到相差的时间
1.months_between(date1,date2);date1和date2相减得到相差的月份. select months_between(to_date('2015-05-11','yyyy ...
随机推荐
- Python poll IO多路复用
一.poll介绍 poll本质上和select没有区别,只是没有了最大连接数(linux上默认1024个)的限制,原因是它基于链表存储的. 本人的另一篇博客讲了 python select : ht ...
- VC++文件拖放
属性Accept Files 设置True,消息WM_DROPFILES 设置事件OnDropFiles void CNWiReworkDlg::OnDropFiles(HDROP hDropInfo ...
- linux/centos6.5下编译安装python2.7和python3.5.2
centos6.5环境下安装python2.7 解压python源码包 tar -xf Python-2.7.6.tar.xz 进入软件包目录 cd Python-2.7.6 添加配置项 ./conf ...
- InetAddress问题
InetAddress的方法 当输入InetAddress.getByAddress(new byte[]{127.0.0.1})的时候不会报错, 但是ip的各段值是0-255,当new byte[] ...
- Memcache是谁,它为什么而奋斗?【内容转】
MemCache是什么 MemCache是一个自由.源码开放.高性能.分布式的分布式内存对象缓存系统,用于动态Web应用以减轻数据库的负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高 ...
- 在vscode成功配置Python环境
注意:如果您希望在Visual Studio Code中开始使用Python,请参阅教程.本文仅关注设置Python解释器/环境的各个方面. Python中的“环境”是Python程序运行的上下文.环 ...
- PHP时间类完整实例
<?php header("Content-type:text/html;Charset=utf-8"); class time{ private $year;//年 pri ...
- Python 索引迭代
1.使用enumerate函数 L = ['Adam', 'Lisa', 'Bart', 'Paul'] for index, name in enumerate(L): print inde ...
- 安装httpd过程,将网站部署到httpd过程
1,配置DNSvi /etc/resolv.conf 加入以下代码 nameserver 192.168.0.1 nameserver 8.8.8.8 nameserver 8.8.4.4 2.输入y ...
- ERP简介(一)
ERP是针对物资资源管理(物流).人力资源管理(人流).财务资源管理(财流).信息资源管理(信息流)集成一体化的企业管理软件 一:系统模块简介: