当前位置:网站首页>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
边栏推荐
- JVM (19) -- bytecode and class loading (4) -- talk about class loader again
- High voltage leakage relay bld-20
- Dj-zbs2 leakage relay
- 利用OPNET进行网络单播(一服务器多客户端)仿真的设计、配置及注意点
- Leakage relay llj-100fs
- Leakage relay jd1-100
- Mapbox Chinese map address
- 基于NCF的多模块协同实例
- ForkJoin最全详解(从原理设计到使用图解)
- JVM (XX) -- performance monitoring and tuning (I) -- Overview
猜你喜欢
张平安:加快云上数字创新,共建产业智慧生态
Jhok-zbg2 leakage relay
Dj-zbs2 leakage relay
SAP webservice 测试出现404 Not found Service cannot be reached
K6el-100 leakage relay
5. Data access - entityframework integration
论文阅读【Semantic Tag Augmented XlanV Model for Video Captioning】
Use, configuration and points for attention of network layer protocol (taking QoS as an example) when using OPNET for network simulation
sql优化常用技巧及理解
Digital innovation driven guide
随机推荐
Flink SQL 实现读写redis,并动态生成Hset key
Unity keeps the camera behind and above the player
【js组件】自定义select
1. AVL tree: left-right rotation -bite
Mybaits之多表查询(联合查询、嵌套查询)
分布式事务解决方案之TCC
Life experience of an update statement
Safe landing practice of software supply chain under salesforce containerized ISV scenario
Is the human body sensor easy to use? How to use it? Which do you buy between aqara green rice and Xiaomi
拼多多商品详情接口、拼多多商品基本信息、拼多多商品属性接口
TabLayout修改自定义的Tab标题不生效问题
Différenciation et introduction des services groupés, distribués et microservices
不同网段之间实现GDB远程调试功能
5. 数据访问 - EntityFramework集成
Zhang Ping'an: accelerate cloud digital innovation and jointly build an industrial smart ecosystem
漏电继电器LLJ-100FS
Codeforces Round #416 (Div. 2) D. Vladik and Favorite Game
Lombok插件
Flink SQL realizes reading and writing redis and dynamically generates hset key
Writing process of the first paper