当前位置:网站首页>SQL query: subtract the previous row from the next row and make corresponding calculations
SQL query: subtract the previous row from the next row and make corresponding calculations
2022-07-07 05:39:00 【MonkeyKing_ sunyuhua】
In the project , There is a task of getting a data in an hour , After obtaining the specific value , It needs to be stored in the database . But after long-term accumulation , It is necessary to check whether it is recorded once an hour .
Data like this :
We need statistics , Is there any missing legacy , Is there something missing for an hour ,
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
Query results :
This makes it easy to find , Those places are not once an hour .
Knowledge point : Use sqlite The window function of
select Fields to query from (
select * from (select Row_Number() over ( order by UsageStartDate ) as RN , + My own query sql
) where rn%2=0 ) a
inner join
(
select * from (select Row_Number() over ( order by UsageStartDate ) as RN , + The same query as above SQL
) where rn%2<>0 ) b on a.rn=b.rn-1
边栏推荐
- 1. AVL tree: left-right rotation -bite
- [JS component] custom select
- The navigation bar changes colors according to the route
- DOM node object + time node comprehensive case
- Leakage relay jelr-250fg
- Mybaits multi table query (joint query, nested query)
- 论文阅读【Open-book Video Captioning with Retrieve-Copy-Generate Network】
- Leakage relay llj-100fs
- Tablayout modification of customized tab title does not take effect
- C#可空类型
猜你喜欢
Paper reading [open book video captioning with retrieve copy generate network]
JVM(二十) -- 性能监控与调优(一) -- 概述
[JS component] date display.
[JS component] custom select
sql查询:将下一行减去上一行,并做相应的计算
Lombok插件
K6EL-100漏电继电器
Under the trend of Micah, orebo and apple homekit, how does zhiting stand out?
Leetcode: maximum number of "balloons"
JVM (XX) -- performance monitoring and tuning (I) -- Overview
随机推荐
分布式事务解决方案之TCC
Common skills and understanding of SQL optimization
5. 数据访问 - EntityFramework集成
1.AVL树:左右旋-bite
TabLayout修改自定义的Tab标题不生效问题
利用OPNET进行网络任意源组播(ASM)仿真的设计、配置及注意点
What is dependency injection (DI)
论文阅读【Sensor-Augmented Egocentric-Video Captioning with Dynamic Modal Attention】
MySQL数据库学习(8) -- mysql 内容补充
Make web content editable
基于 hugging face 预训练模型的实体识别智能标注方案:生成doccano要求json格式
How digitalization affects workflow automation
什么是依赖注入(DI)
集群、分布式、微服务的区别和介绍
常用消息队列有哪些?
Paper reading [open book video captioning with retrieve copy generate network]
Under the trend of Micah, orebo and apple homekit, how does zhiting stand out?
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
漏电继电器JD1-100
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