当前位置:网站首页>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
边栏推荐
- 【oracle】简单的日期时间的格式化与排序问题
- Leakage relay llj-100fs
- Digital innovation driven guide
- "Multimodal" concept
- “多模态”概念
- Safe landing practice of software supply chain under salesforce containerized ISV scenario
- [Oracle] simple date and time formatting and sorting problem
- [论文阅读] A Multi-branch Hybrid Transformer Network for Corneal Endothelial Cell Segmentation
- English语法_名词 - 所有格
- JVM(二十) -- 性能监控与调优(一) -- 概述
猜你喜欢
Leetcode 1189 maximum number of "balloons" [map] the leetcode road of heroding
分布式事务解决方案之2PC
4. Object mapping Mapster
Lombok plug-in
JVM(二十) -- 性能监控与调优(一) -- 概述
集群、分布式、微服務的區別和介紹
Paper reading [MM21 pre training for video understanding challenge:video captioning with pre training techniqu]
Phenomenon analysis when Autowired annotation is used for list
消息队列:如何确保消息不会丢失
《2》 Label
随机推荐
漏电继电器JD1-100
Mybaits之多表查询(联合查询、嵌套查询)
基于NCF的多模块协同实例
Vector and class copy constructors
Use, configuration and points for attention of network layer protocol (taking QoS as an example) when using OPNET for network simulation
What is dependency injection (DI)
English语法_名词 - 所有格
《5》 Table
How digitalization affects workflow automation
Mysql database learning (7) -- a brief introduction to pymysql
Mysql database learning (8) -- MySQL content supplement
Leakage relay jd1-100
消息队列:消息积压如何处理?
async / await
Aidl and service
Common skills and understanding of SQL optimization
Simple case of SSM framework
[JS component] date display.
Phenomenon analysis when Autowired annotation is used for list
漏电继电器LLJ-100FS