当前位置:网站首页>Oracle获取最后一条,第一条数据(按时间获取第一条和最后一条数据)
Oracle获取最后一条,第一条数据(按时间获取第一条和最后一条数据)
2022-07-17 00:17:00 【涛声依旧叭】
假设有如下场景:
电表,大家都知道电表读数并不是真正的耗电量,真正耗电量=此次读数-上一次读数
电表设计如下:

SQL语句如下,使用Oracle的FIRST_VALUE()和LAST_VALUE()函数实现:
SELECT
DISTINCT
LAST_VALUE (E_VALUE) OVER (PARTITION BY E_CODE ORDER BY E_DATE ROWS BETWEEN unbounded preceding AND unbounded following) AS LAST_TIME_VALUE,
FIRST_VALUE (E_VALUE) OVER (PARTITION BY E_CODE ORDER BY E_DATE ROWS BETWEEN unbounded preceding AND unbounded following) AS FIRST_TIME_VALUE
FROM
TABLE_TEST结果:

边栏推荐
- When the drain operation is performed on the work node, the number of pod copies is protected through the PDB
- Squid agent service deployment
- [solution] the local Group Policy Editor (gpedit.msc) in Win 11 cannot be opened
- Expect interaction free
- FTP服务
- WINRAR命令拷贝指定文件夹为压缩文件,调用计划任务进行备份。
- An example of C language callback function & sprinf practical application
- 正则、扩展表达式,sed文本处理器与awk工具、用脚本改IP地址
- OSPF综合实验
- Keep two decimal places and take values upward
猜你喜欢
随机推荐
Convert string to integer
Shell script case branch statement, pick the max address of anonymous login FTP
PowerStor500T报错0x01806803
Reprint: SQL injection common bypass
时间管理方法的反思与探讨
数组、冒泡的认识
数组、冒泡的认识
Firewall firewall
Leetcode --- one question per day
升级kubernetes 1.23.2到1.24.1
RHCE8学习指南第一章 安装RHEL8.4
Understanding of array and bubbling
Lintcode 366:fibonacci Fibonacci sequence
Understanding of array and bubbling
Arm cross compiler naming rules
Image quality evaluation indicators: SNR, PSNR, MSE and SSIM
HCIA_RIP实验
Dynamic programming problem - Small Soldiers rush forward
MDK Keil/ARM printf 用法说明
Common English business mail phrases









