当前位置:网站首页>sql查询:将下一行减去上一行,并做相应的计算
sql查询:将下一行减去上一行,并做相应的计算
2022-07-06 23:42:00 【MonkeyKing_sunyuhua】
项目中,有一个小时获取一个数据的任务,获取具体的值后,需要存在数据库中。但是长期累计后,需要检查有没有做到一个小时记录一次。
比如这样的数据:
我们需要统计,有没有遗漏的遗留,是不是有遗漏了一个小时的,
select julianday(b.UsageStartDate)-julianday(a.UsageStartDate),a.UsageStartDate,a.UsageEndDate from (
select * from (select Row_Number() over ( order by UsageStartDate ) as RN , * from "north1-nx-billing" where LinkedAccountId = '621933488636' and ResourceId = 'i-0f2bf6bb9eab43dd5' and UsageType like '%HeavyUsage:m5.large' ORDER BY UsageStartDate
) where rn%2=0 ) a
inner join
(
select * from (select Row_Number() over ( order by UsageStartDate ) as RN , * from "north1-nx-billing" where LinkedAccountId = '621933488636' and ResourceId = 'i-0f2bf6bb9eab43dd5' and UsageType like '%HeavyUsage:m5.large' ORDER BY UsageStartDate
) where rn%2<>0 ) b on a.rn=b.rn-1
查询结果:
这样就和容易查询出来,那些地方不是一个小时一次了。
知识点: 使用sqlite的窗口函数
select 自己要查询的字段 from (
select * from (select Row_Number() over ( order by UsageStartDate ) as RN , + 自己的查询sql
) where rn%2=0 ) a
inner join
(
select * from (select Row_Number() over ( order by UsageStartDate ) as RN , + 和上面一样的查询SQL
) where rn%2<>0 ) b on a.rn=b.rn-1
边栏推荐
- CVE-2021-3156 漏洞复现笔记
- Design, configuration and points for attention of network specified source multicast (SSM) simulation using OPNET
- How digitalization affects workflow automation
- 淘寶商品詳情頁API接口、淘寶商品列錶API接口,淘寶商品銷量API接口,淘寶APP詳情API接口,淘寶詳情API接口
- Design, configuration and points for attention of network unicast (one server, multiple clients) simulation using OPNET
- np. random. Shuffle and np Use swapaxis or transfer with caution
- Taobao commodity details page API interface, Taobao commodity list API interface, Taobao commodity sales API interface, Taobao app details API interface, Taobao details API interface
- LabVIEW is opening a new reference, indicating that the memory is full
- AIDL 与Service
- 漏电继电器JELR-250FG
猜你喜欢
[JS component] date display.
Zhang Ping'an: accelerate cloud digital innovation and jointly build an industrial smart ecosystem
[论文阅读] A Multi-branch Hybrid Transformer Network for Corneal Endothelial Cell Segmentation
拼多多商品详情接口、拼多多商品基本信息、拼多多商品属性接口
[论文阅读] Semi-supervised Left Atrium Segmentation with Mutual Consistency Training
消息队列:消息积压如何处理?
K6el-100 leakage relay
The year of the tiger is coming. Come and make a wish. I heard that the wish will come true
Record a pressure measurement experience summary
JVM(二十) -- 性能监控与调优(一) -- 概述
随机推荐
Reading the paper [sensor enlarged egocentric video captioning with dynamic modal attention]
Safe landing practice of software supply chain under salesforce containerized ISV scenario
CentOS 7.9 installing Oracle 21C Adventures
5. 数据访问 - EntityFramework集成
做自媒体视频剪辑,专业的人会怎么寻找背景音乐素材?
Leetcode (417) -- Pacific Atlantic current problem
Record a pressure measurement experience summary
Paper reading [open book video captioning with retrieve copy generate network]
Intelligent annotation scheme of entity recognition based on hugging Face Pre training model: generate doccano request JSON format
分布式事务介绍
阿里云的神龙架构是怎么工作的 | 科普图解
漏电继电器JELR-250FG
Design, configuration and points for attention of network specified source multicast (SSM) simulation using OPNET
消息队列:如何确保消息不会丢失
删除文件时提示‘源文件名长度大于系统支持的长度’无法删除解决办法
Make web content editable
[Oracle] simple date and time formatting and sorting problem
In memory, I moved from CSDN to blog park!
导航栏根据路由变换颜色
做自媒体,有哪些免费下载视频剪辑素材的网站?