当前位置:网站首页>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
边栏推荐
- app clear data源码追踪
- [reading of the paper] a multi branch hybrid transformer network for channel terminal cell segmentation
- When deleting a file, the prompt "the length of the source file name is greater than the length supported by the system" cannot be deleted. Solution
- Writing process of the first paper
- 做自媒体,有哪些免费下载视频剪辑素材的网站?
- Dbsync adds support for mongodb and ES
- Addressable pre Download
- K6EL-100漏电继电器
- Lombok插件
- Educational Codeforces Round 22 B. The Golden Age
猜你喜欢

Leetcode 1189 maximum number of "balloons" [map] the leetcode road of heroding

论文阅读【Sensor-Augmented Egocentric-Video Captioning with Dynamic Modal Attention】

5. 数据访问 - EntityFramework集成
![[论文阅读] Semi-supervised Left Atrium Segmentation with Mutual Consistency Training](/img/d6/e6db0d76e81e49a83a30f8c1832f09.png)
[论文阅读] Semi-supervised Left Atrium Segmentation with Mutual Consistency Training

Senior programmers must know and master. This article explains in detail the principle of MySQL master-slave synchronization, and recommends collecting

基于 hugging face 预训练模型的实体识别智能标注方案:生成doccano要求json格式

Jhok-zbg2 leakage relay

A cool "ghost" console tool

Cve-2021-3156 vulnerability recurrence notes

Annotation初体验
随机推荐
Make web content editable
设f(x)=∑x^n/n^2,证明f(x)+f(1-x)+lnxln(1-x)=∑1/n^2
Flink SQL 实现读写redis,并动态生成Hset key
The navigation bar changes colors according to the route
JVM(十九) -- 字节码与类的加载(四) -- 再谈类的加载器
Getting started with DES encryption
Mysql database learning (7) -- a brief introduction to pymysql
Reading the paper [sensor enlarged egocentric video captioning with dynamic modal attention]
Tencent cloud database public cloud market ranks top 2!
导航栏根据路由变换颜色
Leetcode (417) -- Pacific Atlantic current problem
How can project managers counter attack with NPDP certificates? Look here
Where is NPDP product manager certification sacred?
Zero sequence aperture of leakage relay jolx-gs62 Φ one hundred
数字化如何影响工作流程自动化
1. AVL tree: left-right rotation -bite
分布式事务解决方案之2PC
Torch optimizer small parsing
Common skills and understanding of SQL optimization
Paper reading [semantic tag enlarged xlnv model for video captioning]