当前位置:网站首页>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
边栏推荐
- Leetcode 1189 maximum number of "balloons" [map] the leetcode road of heroding
- [PM products] what is cognitive load? How to adjust cognitive load reasonably?
- 实现网页内容可编辑
- K6el-100 leakage relay
- Leetcode (46) - Full Permutation
- Writing process of the first paper
- 消息队列:如何确保消息不会丢失
- 漏电继电器JD1-100
- Safe landing practice of software supply chain under salesforce containerized ISV scenario
- [论文阅读] A Multi-branch Hybrid Transformer Network for Corneal Endothelial Cell Segmentation
猜你喜欢
CVE-2021-3156 漏洞复现笔记
Leakage relay jelr-250fg
The year of the tiger is coming. Come and make a wish. I heard that the wish will come true
The navigation bar changes colors according to the route
Intelligent annotation scheme of entity recognition based on hugging Face Pre training model: generate doccano request JSON format
分布式事务介绍
AOSP ~binder communication principle (I) - Overview
Jhok-zbg2 leakage relay
论文阅读【Open-book Video Captioning with Retrieve-Copy-Generate Network】
Reading the paper [sensor enlarged egocentric video captioning with dynamic modal attention]
随机推荐
漏电继电器JD1-100
一条 update 语句的生命经历
Senior programmers must know and master. This article explains in detail the principle of MySQL master-slave synchronization, and recommends collecting
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
论文阅读【Sensor-Augmented Egocentric-Video Captioning with Dynamic Modal Attention】
How does mapbox switch markup languages?
JVM (XX) -- performance monitoring and tuning (I) -- Overview
[PHP SPL notes]
K6el-100 leakage relay
Leetcode (46) - Full Permutation
JVM(二十) -- 性能监控与调优(一) -- 概述
淘宝店铺发布API接口(新),淘宝oAuth2.0店铺商品API接口,淘宝商品发布API接口,淘宝商品上架API接口,一整套发布上架店铺接口对接分享
Use Zhiyun reader to translate statistical genetics books
Design, configuration and points for attention of network specified source multicast (SSM) simulation using OPNET
基于 hugging face 预训练模型的实体识别智能标注方案:生成doccano要求json格式
漏电继电器LLJ-100FS
[论文阅读] Semi-supervised Left Atrium Segmentation with Mutual Consistency Training
Pinduoduo product details interface, pinduoduo product basic information, pinduoduo product attribute interface
How digitalization affects workflow automation
Zero sequence aperture of leakage relay jolx-gs62 Φ one hundred