当前位置:网站首页>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
边栏推荐
- 淘宝商品详情页API接口、淘宝商品列表API接口,淘宝商品销量API接口,淘宝APP详情API接口,淘宝详情API接口
- 4. 对象映射 - Mapping.Mapster
- [Oracle] simple date and time formatting and sorting problem
- Two person game based on bevy game engine and FPGA
- Under the trend of Micah, orebo and apple homekit, how does zhiting stand out?
- Batch size setting skills
- Getting started with DES encryption
- 1.AVL树:左右旋-bite
- English语法_名词 - 所有格
- MySQL数据库学习(8) -- mysql 内容补充
猜你喜欢
漏电继电器JD1-100
DOM node object + time node comprehensive case
A cool "ghost" console tool
4. Object mapping Mapster
Lombok plug-in
JSP setting header information export to excel
WEB架构设计过程
JVM(二十) -- 性能监控与调优(一) -- 概述
sql优化常用技巧及理解
Safe landing practice of software supply chain under salesforce containerized ISV scenario
随机推荐
分布式全局ID生成方案
基于 hugging face 预训练模型的实体识别智能标注方案:生成doccano要求json格式
消息队列:消息积压如何处理?
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
Preliminary practice of niuke.com (9)
TabLayout修改自定义的Tab标题不生效问题
Mysql database learning (8) -- MySQL content supplement
What is dependency injection (DI)
Flink SQL 实现读写redis,并动态生成Hset key
[paper reading] semi supervised left atrium segmentation with mutual consistency training
Paper reading [MM21 pre training for video understanding challenge:video captioning with pre training techniqu]
Zero sequence aperture of leakage relay jolx-gs62 Φ one hundred
Summary of the mean value theorem of higher numbers
Educational Codeforces Round 22 B. The Golden Age
The navigation bar changes colors according to the route
Pytest testing framework -- data driven
Safe landing practice of software supply chain under salesforce containerized ISV scenario
[JS component] date display.
[reading of the paper] a multi branch hybrid transformer network for channel terminal cell segmentation
A cool "ghost" console tool