当前位置:网站首页>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(十九) -- 字节码与类的加载(四) -- 再谈类的加载器
- AIDL 与Service
- [binary tree] binary tree path finding
- 拼多多商品详情接口、拼多多商品基本信息、拼多多商品属性接口
- Vector and class copy constructors
- [论文阅读] A Multi-branch Hybrid Transformer Network for Corneal Endothelial Cell Segmentation
- English grammar_ Noun possessive
- If you want to choose some departments to give priority to OKR, how should you choose pilot departments?
- sql查询:将下一行减去上一行,并做相应的计算
- 分布式事务解决方案之2PC
猜你喜欢
[论文阅读] A Multi-branch Hybrid Transformer Network for Corneal Endothelial Cell Segmentation
Leakage relay jelr-250fg
CentOS 7.9 installing Oracle 21C Adventures
Pinduoduo product details interface, pinduoduo product basic information, pinduoduo product attribute interface
Digital innovation driven guide
Dj-zbs2 leakage relay
WEB架构设计过程
Cve-2021-3156 vulnerability recurrence notes
消息队列:如何确保消息不会丢失
Two person game based on bevy game engine and FPGA
随机推荐
京东商品详情页API接口、京东商品销量API接口、京东商品列表API接口、京东APP详情API接口、京东详情API接口,京东SKU信息接口
Paper reading [MM21 pre training for video understanding challenge:video captioning with pre training techniqu]
【js组件】自定义select
论文阅读【Semantic Tag Augmented XlanV Model for Video Captioning】
Addressable pre Download
5. 数据访问 - EntityFramework集成
集群、分布式、微服务的区别和介绍
Différenciation et introduction des services groupés, distribués et microservices
MySQL数据库学习(8) -- mysql 内容补充
sql查询:将下一行减去上一行,并做相应的计算
Mysql database learning (7) -- a brief introduction to pymysql
SAP webservice 测试出现404 Not found Service cannot be reached
论文阅读【Sensor-Augmented Egocentric-Video Captioning with Dynamic Modal Attention】
Pytest testing framework -- data driven
Lombok插件
基于 hugging face 预训练模型的实体识别智能标注方案:生成doccano要求json格式
Egr-20uscm ground fault relay
不同网段之间实现GDB远程调试功能
Flink SQL realizes reading and writing redis and dynamically generates hset key
How Alibaba cloud's DPCA architecture works | popular science diagram